Why the JVM Young Generation Includes Two Survivor Spaces
The article explains the purpose of Survivor spaces in the JVM young generation, how they reduce premature promotion to the old generation, prevent fragmentation, and improve garbage‑collection efficiency by using two alternating survivor areas.
This article discusses why the JVM young generation memory includes not only the Eden space but also two Survivor spaces, providing a detailed explanation for Java interview preparation.
Without Survivor spaces, every Minor GC would promote surviving objects directly to the old generation, quickly filling it and triggering costly Full GCs that significantly impact application performance and response time.
Survivor spaces act as a pre‑filter, allowing only objects that survive multiple Minor GCs (up to 16 cycles) to be promoted, thereby reducing the frequency of Full GCs.
Having two Survivor spaces (S0 and S1) solves fragmentation: after each Minor GC, surviving objects are copied from Eden to one Survivor space, which is then cleared; the next Minor GC copies objects from Eden and the occupied Survivor space into the other Survivor space, ensuring that the receiving space remains contiguous and free of fragmentation.
This alternating copy algorithm guarantees that at any time one Survivor space is empty, providing continuous memory for object allocation and avoiding the risks associated with memory fragmentation. The article concludes that two Survivor spaces represent an optimal trade‑off, as further subdivision would make each space too small and prone to overflow.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.