Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Go subject to the same subtle memory-leaks that Java is?

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?

like image 838
SyntaxT3rr0r Avatar asked Dec 09 '10 16:12

SyntaxT3rr0r


People also ask

Are there memory leaks in Java?

These unintentional object references prevent the built-in Java garbage collection mechanism from freeing up the memory consumed by these objects. Common causes for these memory leaks are: Excessive session objects. Insertion without deletion into Collection objects.


1 Answers

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.

like image 74
james Avatar answered Sep 19 '22 15:09

james