OS & Systems FundamentalsGarbage Collection FundamentalsMedium⏱️ ~2 min

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.

⚠️ Key Trade-off: Generational GC assumes most objects die young. Workloads that create many long lived objects (large caches, connection pools) defeat this assumption. Objects promote quickly, filling old generation and triggering expensive major GCs.
💡 Key Takeaways
Generational hypothesis: 80 to 95 percent of objects die young
Young generation: small, collected frequently with fast minor GCs
Eden plus survivor spaces: objects promote after surviving multiple collections
Region based: heap divided into equal regions, collected incrementally
Garbage first: prioritize collecting regions with most garbage
📌 Interview Tips
1Explain why minor GCs are fast: young generation is small and mostly garbage, so copying survivors is quick
2When asked about GC tuning, mention that large caches can defeat generational hypothesis by quickly promoting to old gen
3Describe G1 region based approach: equal sized regions enable incremental collection without full heap scans
← Back to Garbage Collection Fundamentals Overview