Java / Java 17 Garbage Collection Interview Questions
How does G1 GC divide the heap into regions?
G1 splits the heap into many equal-sized regions, sized as a power of two between 1MB and 32MB, chosen automatically based on heap size (targeting roughly 2048 regions total) or overridden explicitly with -XX:G1HeapRegionSize.
Unlike the fixed, contiguous young/old layout used by Parallel or Serial GC, any region can be dynamically labeled Eden, Survivor, Old, or Humongous at different points in time, and the set of regions that make up the "young generation" simply grows or shrinks as G1 relabels regions.
This flexibility is what lets G1 collect a subset of regions - whichever have the most garbage - in a single pause instead of being forced to scan an entire fixed generation.
More Related questions...