G1GC vs. ZGC vs. Shenandoah for Kubernetes 1.35 In-Place Pod Resize
When a pod shrinks in place, the JVM has to hand memory back to the operating system before the new limit applies. I tested how G1, ZGC and Shenandoah do that in a Linux container. All three released memory quickly in my test, but they differ in what triggers the release and in what SoftMaxHeapSize does. G1 accepts that flag and silently ignores it.
The short answer
ZGC and Shenandoah: SoftMaxHeapSize works at runtime. Lower it, run GC.run , and memory drops.
G1: SoftMaxHeapSize is accepted by jcmd and has no effect. By default nothing returns memory. Two things did, in my test: an explicit GC.run , and G1PeriodicGCInterval set to a few seconds.
Release speed: I measured no real difference. Each collector released a 300 MB working set within about 1 to 7 seconds. I did not measure large heaps or busy applications, which is where I'd expect differences, so treat "G1 is slower" as unproven.
The real G1 difference is the missing ceiling.β¦