Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Garbage Collection

I was wondering about the garbage collection that takes place in Java. Is it really able to handle all objects that aren't used and free up the most possible memory?

I also want to know how does the Java garbage collection compare to another language like lets say C#? And then, how does the automatic garbage collection measure up against manual collection from a language like C?

like image 524
Pieter van Niekerk Avatar asked May 26 '10 05:05

Pieter van Niekerk


1 Answers

Yes, thats the point of garbage collection.

There are many different forms of garbage collection. The simplest form, reference counting, is not able to handle certain type of garbage (circular references) without enhancements to the algorithm.

Java (the Sun JVM) uses a generational mark and sweep collector, though this is not standardized and different JVMs do use different collectors. I do not know the exact collector used by the .NET CLR.

Garbage collectors like reduce programmer overhead, and can make certain algorithms perform better. However, their memory footprint is generally larger than a tight manual allocation system.

The defacto reference on this topic is the book Garbage Collection, which is well written and comprehensive.

like image 183
Yann Ramin Avatar answered Sep 23 '22 20:09

Yann Ramin