Why Does the JVM Use Two Survivor Spaces? Uncover the Memory Management Secrets
This article explains the purpose of Survivor spaces in the JVM young generation, why a single Survivor area is insufficient, how having two Survivor spaces prevents memory fragmentation, and the copy algorithm that keeps one space empty while the other holds contiguous live objects.
1. Why Have a Survivor Space
Without a Survivor space, every Minor GC would move surviving objects directly to the old generation, quickly filling it and triggering Full GCs that are far more time‑consuming, degrading application performance and causing possible time‑outs.
The main benefit of a Survivor space is to pre‑filter objects: only those that survive many Minor GCs (typically 16) are promoted to the old generation, reducing the frequency of Full GCs.
2. Why Two Survivor Spaces
Having two Survivor spaces solves the fragmentation problem. After the first Minor GC, live objects from Eden are copied to the first Survivor space (S0). When Eden fills again, a second Minor GC copies live objects from Eden and S0 into the second Survivor space (S1), leaving S0 empty. The roles of S0 and S1 then swap for the next cycle.
This copy algorithm guarantees that at any moment one Survivor space is completely empty while the other contains only contiguous live objects, eliminating memory fragmentation.
Dividing the Survivor area into more than two spaces would make each space too small, increasing the chance of them filling up and negating the benefits; therefore, two Survivor spaces represent the optimal trade‑off.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
