Java / Java 17 Garbage Collection Interview Questions
How does the JVM decide when to trigger a GC cycle?
The trigger differs by generation and collector. A minor GC fires whenever a thread can't satisfy a new allocation from Eden - there's simply no space left in the young generation's active area.
For G1's concurrent marking cycle, the trigger is based on -XX:InitiatingHeapOccupancyPercent (IHOP, default 45% of old-gen capacity occupied); G1 also supports an adaptive IHOP mode that predicts the right moment to start marking based on recent allocation rate, rather than using a fixed static percentage.
Full GCs are triggered as a fallback rather than on a schedule - most commonly an evacuation failure (G1 runs out of space to copy live objects during a pause), severe Metaspace pressure, or an explicit System.gc() call that the JVM chooses to honor.
More Related questions...