Generational and Region Based Garbage Collection
Generational Hypothesis
Most objects die young. Typical allocation patterns show 80 to 95 percent of objects become garbage within milliseconds of creation. Temporary variables, intermediate results, and short lived buffers dominate allocation. Long lived objects are the minority.
Generational GC exploits this. Divide heap into young generation and old generation. Collect young generation frequently with fast minor collections. Promote survivors to old generation. Collect old generation rarely with slower major collections.
Young Generation Collection
Young generation is small, typically 10 to 20 percent of heap. Minor GC happens frequently, every few seconds or less. Since most young objects are garbage, minor GC is fast: only copy the few survivors to old generation.
Eden space holds new allocations. Survivor spaces hold objects that survived previous minor GCs. After several survivals (typically 15), objects promote to old generation. This filtering ensures only truly long lived objects reach old generation.
Region Based Collection
Modern GCs like G1 divide the heap into equal sized regions. Each region is independently collected. This enables incremental collection: collect some regions per cycle instead of the entire old generation at once.
Region based collectors can prioritize garbage first regions. A region that is 90 percent garbage yields more free memory than a region that is 10 percent garbage. By collecting high garbage regions first, the collector maximizes freed memory per time spent collecting.