I read at many places, but did not find a place where I can learn about :
What is java garbage collection all about?
How is it implemented?
When and how is it called ?
What algorithms if follows in order to reclaim memory ??
In short everything about it :)
FIXED!!!
A very good article : http://www.artima.com/insidejvm/ed2/gcP.html
The mark-and-sweep algorithm is called a tracing garbage collector because it traces out the entire collection of objects that are directly or indirectly accessible by the program. Example: A. All the objects have their marked bits set to false.
Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.
Excessive garbage collection activity can occur due to a memory leak in the Java application. Insufficient memory allocation to the JVM can also result in increased garbage collection activity. And when excessive garbage collection activity happens, it often manifests as increased CPU usage of the JVM!
The very short version of answers are:
What is java garbage collection all about?
GC is a mechanism of memory management where the system (the JVM in this case) is responsible for automatically reclaiming memory that is no longer in use.
How is it implemented?
There are various ways to implement it. A simple description is that each piece of memory that is allocated is tracked. periodically the system checks the allocated pieces to see if any part of the program (the variables) can still reach the memory. Any memory that cannot be reached is reclaimed.
When and how is it called ?
This is also left up to the implementation. The only guarantee you have in Java is that before an OutOfMemoryError is thrown the system will attempt to reclaim memory. I would expect that most GC implementations also try to do a collection before they ask the underlying operating system for more memory. In general there will be a background thread that deals with running the collector.
What algorithms if follows in order to reclaim memory ??
There are several possible ones. Look at the articles others have posted as a starting point for that.
The Wikipedia entry for garbage collection covers all your questions:
http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
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