Java / JVM Architecture (Java21) Interview questions
Why does the JVM use generational garbage collection?
Generational collection is built on an empirical observation called the weak generational hypothesis: most objects die young, and the few that survive tend to live a very long time.
By segregating new objects into a small Young Generation, the collector can run frequent, cheap Minor GCs that only scan that small region - since most of what's there is already garbage, these collections reclaim a lot of memory very quickly.
The Old Generation, holding the smaller set of long-lived survivors, is scanned far less often, avoiding the cost of repeatedly re-examining objects that are known to still be alive.
Without this split, every collection would have to scan the entire heap regardless of how likely any given object was to still be reachable, which would make garbage collection dramatically more expensive on any heap of meaningful size.
More Related questions...