Go是否受到与Java相同的微妙内存泄漏? [英] Is Go subject to the same subtle memory-leaks that Java is?

查看:93
本文介绍了Go是否受到与Java相同的微妙内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是事实:


  • 语言Go有一个垃圾收集器。

  • Java有一个垃圾回收不是)内存泄漏


作为一个有内存泄漏的Java程序的例子这个问题可能会动摇你的信念),在这里看到一个叫Tomcat的小程序,它甚至有一个find leaks按钮:有没有办法避免在Tomcat中取消部署内存泄露?



所以我想知道:用Go编写的程序是否会展现出与内存泄漏相同的内容用Java编写的程序展现出来?

解决方案

你在这里混淆了不同类型的内存泄漏。

在Java(或任何其他基于GC的语言)中,基于内存,显式内存管理的内存泄漏消失了。这些泄漏是由于完全失去对大块内存的访问而没有将它们标记为未使用而造成的。


内存泄漏仍然存在于Java和所有其他语言中直到计算机能够读懂我们思想的星球仍然与我们在一起,并将在可预见的将来。这些泄漏是由代码/程序员保留对技术上不再需要的对象的引用引起的。这些从根本上说是逻辑错误,并且不能用任何使用现有技术的语言阻止。

Here are the facts:

  • the language Go has a garbage collector.

  • Java has a garbage collection

  • a lot of Java programs have (subtle or not) memory leaks

As an example of a Java program that has memory leaks (not for the faint of heart, the question may shake your beliefs), see here about a little Java program called Tomcat that even has a "find leaks" button: Is there a way to avoid undeployment memory leaks in Tomcat?

So I am wondering: will programs written in Go exhibit the same kind of (subtle or not) memory leaks that some programs written in Java exhibit?

解决方案

You are confusing different types of memory leaks here.

The heinous, explicit-memory-management based memory leaks are gone in Java (or any other GC based language). These leaks are caused by completely losing access to chunks of memory without marking them as unused.

The "memory leaks" still present in Java and every other language on the face of the planet until the computer can read our minds are still with us, and will be for the foreseeable future. These leaks are caused by the code/programmer keeping references to objects which are technically no longer needed. These are fundamentally logic bugs, and cannot be prevented in any language using current technologies.

这篇关于Go是否受到与Java相同的微妙内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆