What is Java Heap Space and Garbage Collection?
The Java Heap Space is the memory “container” of a run time Java program providing the proper memory spaces that it needs (Java Heap, Native Heap). It is managed by the JVM itself.
What is Garbage Collection (GC)?
Garbage collection is the process of automatically freeing objects no longer referenced by the program.
- Common tracing algorithm is known as mark and sweep
– mark phase – GC traverses reference tree, marking objects
– sweep phase – umarked objects are finalized/freed
- Two strategies to reduce fragmentation
– Mark-Compact Collector – After the mark phase, moves live objects to a contiguous area in the heap.
– Copy Collector – moves live objects to a new area