Generational Garbage Collection Pipeline
Understand generational garbage collection visually. Follow how JVM-style runtimes manage memory through Eden, Survivor spaces (S0/S1), and the Old Generation
Continue with the guided workspace
Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.
Mental Model
The weak generational hypothesis states that most allocated objects are short-lived. To exploit this, generational GC divides the heap into separate zones. Eden receives new allocations. When Eden fills, a Minor GC copies surviving objects to a Survivor space (S0 or S1) and increments their age. Subsequent Minor GCs copy survivors back and forth between S0 and S1. Objects surviving enough cycles are promoted to the Old Generation, which undergoes less frequent, more intensive Major GCs.
Components and Why They Exist
GC Roots
GC roots are the baseline starting points for liveness analysis, representing local variables, static fields, and active threads. They serve as the anchors of the reachability graph; any object that cannot be traced from the GC Roots card is treated as unreachable garbage.
Eden Space
Eden space is the primary landing strip where mutator threads allocate all new objects. It accumulates young allocations until capacity is reached and triggers a Minor GC, which copies live survivors out and clears the entire Eden panel in one pass.
Survivor Spaces (S0 / S1)
The survivor spaces (S0 and S1) provide a middle ground where objects age before promotion to the Old Generation, preventing short-lived objects from polluting long-term storage. One survivor space is kept completely empty so live objects can be copied sequentially from Eden and the active survivor space during a Minor GC, swapping S0/S1 roles and incrementing each survivorβs tenuring age counter.
Old Generation (Tenured Space)
The Old Generation stores long-lived objects that have survived multiple young collection cycles. This region manages memory for persistent data and triggers a Major GC (Full GC) when capacity is reached, promoting aged objects from S0/S1 and sliding surviving blocks to one end during compaction.
Edge Cases and Misconceptions
- Misconception: Objects are promoted to Old Gen based on their size: While some runtimes promote very large objects directly to Old Gen, the primary mechanism is tenuring age (how many minor collection cycles they survive).
- Misconception: Survivor spaces swap roles continuously during application run: Roles only swap during a Minor GC cycle. Between GCs, one is active (receives survivors) and the other remains idle and empty.
- Edge Case: Premature Promotion: If the young generation is too small, survivor spaces overflow, forcing young objects to be promoted to Old Gen prematurely. This fills Old Gen quickly, triggering expensive Major GC cycles.
Common Questions
Why do we swap between Survivor 0 (S0) and Survivor 1 (S1) spaces?
Swapping survivor roles ensures that one survivor space is always 100% empty. During a minor GC, all live objects are compacted sequentially into the empty space. This avoids memory fragmentation in the young generation entirely.
What triggers a Major GC, and how does it differ from a Minor GC?
A Minor GC collects only the Young Generation (Eden and Survivor spaces) and is very fast. A Major GC (or Full GC) is triggered when the Old Generation fills up. It scans a much larger volume of objects and requires a Mark-Sweep-Compact cycle, leading to longer Stop-The-World pauses.
What is the weak generational hypothesis?
It is the empirical observation that 'most objects die young.' Generational garbage collection is designed around this rule to optimize execution performance by focusing collection efforts on young, short-lived allocations.
What is a write barrier in generational garbage collection?
When an object in the Old Gen is modified to reference a Young Gen object, the GC must track this reference so it does not collect the Young Gen object during a Minor GC. A write barrier intercepts reference updates and records them in a card table or remembered set, avoiding scanning the entire Old Gen.