Garbage Collection Flashcards
What is garbage collection?
The internal mechanism to reclaim the memory of unused objects at runtime. Also known as automatic memory management.
Why does java provide garbage collection?
Since memory management is provided by the JVM in Java, after some time the JVM may run low on memory. The JVM must then free memory from unused objects. To help with the process of reclaiming memory, Java provides automatic memory management.
What is the purpose of .gc( ) ?
Java provides two methods System.gc( ) and Runtime.gc( ) to explicitly send a request for Garbage Collection to run.
How does garbage collection work?
When the JVM is low on memory, GC process finds the unused objects that are not referenced by other objects. This objects are then cleaned up by the Garbage Collector daemon in JVM.
When does an object become eligible for Garbage Collection?
If the object is not reachable, e.g an object/instance that cannot be reached by a live thread. A set of circularly referenced instances that cannot be reached by any other instance outside that set.
What kind of process is the Garbage collector thread?
A daemon process in JVM. An internal process that keeps checking memory usage and cleans up the memory.