Java / Java 17 Garbage Collection Interview Questions
What is a full GC?
A full GC collects the entire heap - young generation, old generation, and typically triggers a Metaspace cleanup pass too - in one operation, and in most collectors it's a fully stop-the-world, single-threaded compaction.
It's the most expensive kind of collection the JVM can run, so it's normally treated as a fallback rather than routine behavior: it happens when a regular collection can't keep up, for example when G1 hits an evacuation failure (not enough free regions to copy live objects into), when Metaspace is exhausted, or when code calls System.gc() and the JVM honors it.
| Type | Scope | Typical cost |
| Minor GC | Young generation only | Low, frequent |
| Major GC | Old generation (collector-dependent) | Moderate, occasional |
| Full GC | Entire heap + Metaspace pass | High, rare / fallback |
Seeing full GCs on a regular cadence in production logs is almost always a signal worth investigating - it usually means the heap is undersized, there's a memory leak, or the allocation rate is spiking faster than the collector can keep pace with.
More Related questions...