Java / JVM Architecture (Java21) Interview questions
Explain the execution flow of a Minor GC vs Major GC?
A Minor GC collects only the Young Generation, while a Major GC, often triggered together with what's called a Full GC, also collects the Old Generation.
flowchart TD
A[Object allocated in Eden] --> B{Eden fills up}
B --> C[Minor GC: copy live objects Eden to Survivor]
C --> D{Object survives enough cycles?}
D -- No --> E[Object dies in Young Gen]
D -- Yes --> F[Promoted to Old Generation]
F --> G{Old Generation fills up}
G --> H[Major/Full GC: scan and reclaim Old Gen, may pause longer]
A Minor GC is fast because it only ever touches the small Young Generation and most of what it finds is already dead; a Major GC is more expensive because the Old Generation is larger and typically has a much higher proportion of live, reachable objects, meaning more work per byte scanned.
More Related questions...