Java / Java 17 Garbage Collection Interview Questions
What are the types of garbage collectors available in Java 17?
Java 17 ships with five usable collectors, plus one purely diagnostic collector, each selected with its own JVM flag:
| Collector | Flag | Best suited for |
| Serial GC | -XX:+UseSerialGC | Small heaps, single-core machines |
| Parallel GC | -XX:+UseParallelGC | Batch jobs prioritizing raw throughput |
| G1 GC | -XX:+UseG1GC (default) | Balanced throughput and pause predictability |
| ZGC | -XX:+UseZGC | Very large heaps needing sub-10ms pauses |
| Shenandoah | -XX:+UseShenandoahGC | Low pause times independent of heap size |
| Epsilon | -XX:+UseEpsilonGC | No-op collector for perf testing, never reclaims |
Note that CMS (Concurrent Mark Sweep) is not in this list - it was deprecated in JDK 9 and fully removed in JDK 14, so it is not an option on Java 17.
More Related questions...