A Java service that caches a few million objects eventually has to throw them away, and how it does so determines whether users see a smooth response time or a periodic freeze. For years the default collector was G1, which broke the heap into regions and cleaned a few at a time to keep pauses short. ZGC changed the bargain: it moves objects while the program is still running, so even a heap measured in terabytes pauses for roughly the time it takes to stop the threads at a safepoint.
G1 keeps pause times in the tens of milliseconds by collecting in small region increments, while ZGC keeps them under a millisecond regardless of heap size by doing the compaction work concurrently with the application — the price is extra CPU and heap headroom.
The decision is not about which collector is newer. It is about what you are willing to spend to remove a specific kind of latency, because both collectors eventually reclaim the same garbage and both keep the program correct.
Part One: What is being compared
G1 treats the heap as a set of equal-sized regions and maintains a list of which ones are mostly garbage. It collects the cheapest regions first, and it can pause the application to move the surviving objects of a few regions into fresh ones. That pause is proportional to the number of regions it handles in one cycle, which the collector can bound with a pause target. Set a 50 millisecond goal and G1 will try to do only enough work per cycle to hit it, leaving the rest for later.
The consequence is that G1 pauses grow with the amount of live data it must evacuate in a cycle. Under a large, long-lived cache, the regions it picks contain more survivors, each cycle has more copying to do, and meeting a tight target gets harder. G1 also needs a remembered set per region to track references from elsewhere, and those structures consume memory and CPU on every write.
A ZGC cycle uses coloured pointers and load barriers to relocate objects while application threads keep running, so its pause is a safepoint of well under a millisecond — but the load barrier touches every reference read and the collector needs roughly 15 to 30 percent heap headroom to stay ahead of allocation.
Part Two: The mechanism
ZGC takes a different route. It encodes metadata in the pointer bits themselves, using coloured pointers to mark whether an object has been moved, and it intercepts reference loads with a barrier that forwards the program to the new location. Because the program never sees a stale pointer, the collector can relocate objects concurrently with normal execution. Only a tiny phase at the start and end of a cycle needs to stop the threads, and that stop does not scale with heap size.
The mechanism has a cost on every access. A load barrier is a few extra instructions on each reference read, and in pointer-heavy workloads the cumulative overhead can reach single-digit to low double-digit percentages of throughput. ZGC also needs spare memory: it cannot compact into a full heap, so it relies on headroom and on allocating into a new region while the old one is being emptied. Give it too little and it will stall the application just like any other collector.
Part Three: Where it shows up
Where this shows up in ordinary life is the page that takes a second to load at the same moment every afternoon. A batch job finishes, the young generation fills, G1 pauses to evacuate, and the request queue backs up for a few dozen milliseconds. Users do not know about garbage collection, but they feel the pause as a spinner. A trading dashboard or a checkout flow is exactly where that spinner becomes a lost order.
The comparison also depends on how much memory a machine has. On a service with a two gigabyte heap, G1 is easy to tune and its pauses are already small enough that nobody notices. On a fifty gigabyte in-memory index, the same pause target forces G1 into a losing race with allocation, while ZGC keeps the pause flat and simply asks for more RAM and CPU.
Choose G1 when pauses in the tens of milliseconds are invisible and you want predictable throughput from modest hardware; choose ZGC when a sub-millisecond tail matters more than the CPU and memory you will spend to get it — the collector is a budget decision, not a ranking.
What is actually transferable
For a small service, the practical advice is to stay with the default and measure before changing anything. Turning on ZGC without a latency problem just moves cost from a rare pause into every reference read. For a latency-critical service with a large heap, the opposite is true: the steady tax is worth paying to delete the tail.
The deeper lesson is that garbage collectors trade one kind of cost for another. G1 spreads the cost into occasional stops; ZGC spreads it into continuous small overheads. Neither removes the work of reclaiming memory, so the question is always where you would rather pay it.
Market sizing check
The JVM runs a large share of enterprise backend services, and server-side Java deployments are commonly counted in the tens of millions of instances worldwide. Even if a fraction of those adopt low-latency collectors for latency-sensitive tiers, the extra memory headroom ZGC asks for translates into meaningful additional RAM per instance — a purchase decision measured in millions of servers rather than a theoretical preference.
These are order-of-magnitude estimates from published adoption ranges and stated assumptions, not a forecast for any vendor.
The comparison that matters
G1 caps pauses by collecting young regions incrementally; ZGC moves objects concurrently and keeps pauses flat even at multi-terabyte heaps — at a CPU and memory tax.
Creating this takes real effort — thank you for the support.
HCqPmPJM3NVtS6YrmVaTZYnuP8XZ2PFgQZKT94VK1LkS
