Last Updated: June 6, 2026
The previous chapter covered the general idea of garbage collection: reachability, the generational hypothesis, and the basic mark-sweep approach. This chapter is about the actual collectors HotSpot ships, what each one is good at, and how to pick one for a real workload. The Java runtime doesn't ship with "garbage collection" as a single thing. It ships with a handful of distinct collectors, each tuned for a different shape of application. The appropriate choice for a checkout API differs from the choice for an overnight reporting job, and the choice for a one-shot CLI tool isn't a real collector at all.
This chapter covers the role of each -XX:+Use...GC flag, the behavior of each collector, and how to make a defensible production choice.