All 15 Garbage Collection questions
More in Garbage Collection
Advertisement
Java › Garbage Collection

How does the generational hypothesis (most objects die young) inform the JVM's generational heap structure (young generation, old generation), and how does a minor GC differ from a major/full GC?

Intermediate

Answer

The generational hypothesis observes that in typical applications, the vast majority of objects become garbage very shortly after creation (like short-lived local variables or temporary calculation results), while a much smaller fraction survive long enough to become long-lived -- the JVM heap is divided accordingly into a young generation (further split into Eden and two Survivor spaces, where new objects are allocated and most die quickly) and an old/tenured generation (holding objects that have survived multiple young-generation collections) -- a minor GC (frequent, fast) only collects the young generation, while a major/full GC (much less frequent, but significantly more expensive) collects the old generation (and often the entire heap), with this generational split letting the JVM apply cheap, frequent collection specifically where most garbage actually occurs.
// Conceptual illustration of generational promotion (not actual code, just illustrating the process)
// 1. New objects allocated in Eden space
// 2. Eden fills up -> minor GC triggers, surviving objects move to a Survivor space
// 3. Objects surviving several minor GCs get PROMOTED to the old generation
// 4. Old generation eventually fills up -> a much more expensive major/full GC occurs
Real-world example A web application generating thousands of short-lived request-scoped objects per second experiences frequent but very fast minor GCs (since almost all these objects die in the young generation almost immediately), while a much rarer full GC only occurs when the smaller set of genuinely long-lived objects (like cached configuration data) in the old generation eventually needs to be collected.

Common follow-ups: What determines how many minor GC survivals it takes before an object gets promoted to the old generation?;Why is a major/full GC typically so much more expensive than a minor GC?