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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With