
Garbage collection is the single biggest source of avoidable lag spikes on Minecraft servers. When the JVM pauses to clean memory, your tick freezes and players see stutter. G1GC and ZGC handle this very differently. G1GC does part of its work in stop-the-world pauses, with a default pause goal of 200 ms. ZGC does its expensive work while the server keeps running and keeps pauses under a millisecond, whatever the heap size (Oracle ZGC guide). On a big heap where G1 pauses line up with your lag spikes, that difference is what removes them.
Below: how each collector works, how to check whether GC is really your problem, and which one we recommend for vanilla, Paper, and big modpacks.
ZGC Flags to Copy
Pick the line that matches your server's Java version. Minecraft 1.20.5 through 1.21.11 run on Java 21. Minecraft 26.1 was the first release to require Java 25, and 26.2 and 26.3 use Java 25 as well.
Java 25 (Minecraft 26.1 to 26.3):
-Xms12G -Xmx12G -XX:+UseZGC -XX:+AlwaysPreTouch -XX:+DisableExplicitGC
Java 21 (Minecraft 1.20.5 to 1.21.11):
-Xms12G -Xmx12G -XX:+UseZGC -XX:+ZGenerational -XX:+AlwaysPreTouch -XX:+DisableExplicitGC
Change both 12G values to your heap size and leave some RAM free for the operating system. The line replaces your old GC flags and goes before -jar in your start command. On Space-Node you set it in the Startup tab.
Why the Java 21 line is longer: on Java 21, plain -XX:+UseZGC still runs the older non-generational ZGC, so you add -XX:+ZGenerational (JEP 439). Java 23 made generational mode the default (JEP 474) and Java 24 removed the old mode. On Java 25, -XX:+UseZGC alone gives you generational ZGC, and -XX:+ZGenerational only prints an obsolete option warning (JEP 490). The same JEP says a later JDK will stop recognizing the flag and refuse to start, so remove it now.
Neither line needs -XX:+UnlockExperimentalVMOptions. ZGC has been a regular product feature since JDK 15 (JEP 377), and none of the flags above are experimental.
G1GC or ZGC: Rule of Thumb
- Heap under about 12GB, or CPU already busy: stay on G1GC with Aikar's flags. G1 is the JVM's default collector on most hardware and aims to meet a pause time goal while keeping throughput high (Oracle GC tuning guide). Paper's recommended startup flags are built on G1 (PaperMC docs).
- Heap of 12GB and up, with GC pauses showing up as lag: test ZGC. Oracle describes ZGC as keeping pauses under a millisecond at the cost of some throughput, with pause times that do not grow with heap size.
- Give ZGC more RAM, not the same RAM: ZGC collects while the server keeps running, so the heap needs headroom for new objects during a collection. Oracle's own advice is that the more memory you give ZGC, the better (Oracle ZGC guide).
- Check first:
/spark gcprints the server's GC history and/spark gcmonitortoggles live GC monitoring (spark docs). If GC pauses do not line up with your lag spikes, switching collectors will not fix them.
The 12GB line is our own starting point, not a limit set by the JDK.
What Is Garbage Collection
Minecraft constantly creates and destroys objects in memory. Java's garbage collector reclaims unused memory. During collection, the server pauses briefly. Long or frequent pauses cause TPS drops and player-visible lag.
G1GC (Garbage First)
G1GC is the default garbage collector for Minecraft. It is what Aikar's flags are tuned for.
How G1GC Works
- Divides the heap into equally sized regions
- Collects the regions with the most garbage first, hence the name
- Tries to keep pauses under a target time (
MaxGCPauseMillis, 200 ms by default) - Marks live objects concurrently, but copies objects out of regions in stop-the-world pauses (Oracle G1 guide)
G1GC Pros
- Well-tested with Minecraft
- Aikar's flags optimize it specifically
- Consistent performance
- Good for 4 to 16 GB heap sizes
G1GC Cons
- Young and mixed collections pause the whole server while they run
- With large heaps and a lot of live data, pauses can get longer
- Cannot fully avoid stop-the-world pauses
Recommended G1GC Flags (Aikar's)
-XX:+UseG1GC -XX:+ParallelRefProcEnabled
-XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions
-XX:+DisableExplicitGC -XX:+AlwaysPreTouch
-XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4
-XX:G1MixedGCLiveThresholdPercent=90
This is a shortened set. Keep -XX:+UnlockExperimentalVMOptions in it: G1MixedGCLiveThresholdPercent is an experimental option on both Java 21 and Java 25, and the JVM will not accept it without the unlock flag. The full Aikar's line, with G1NewSizePercent and the other young generation settings, is in the PaperMC docs and in our Aikar's flags guide.
ZGC (Z Garbage Collector)
ZGC is designed for low-latency applications. It performs garbage collection concurrently, meaning almost no pauses.
How ZGC Works
- Collects garbage concurrently with the application
- Pause times under 1ms regardless of heap size
- Uses colored pointers and load barriers
- Scales to terabytes of heap
ZGC Pros
- Pauses under a millisecond
- Pauses do not grow with heap size
- GC pauses stop being a cause of TPS drops (other causes remain)
- Suited to large heaps
ZGC Cons
- Some throughput cost: the concurrent GC threads use CPU time
- Needs heap headroom, so the server can keep allocating while a collection runs
- Less tested with Minecraft than G1GC
- Aikar's flags do not apply
Recommended ZGC Flags
Use the Java 25 or Java 21 line from "ZGC Flags to Copy" at the top of this page. What each flag does:
-XX:+UseZGCswitches the server to ZGC. From Java 23 on, this is generational ZGC by default.-XX:+ZGenerationalis for Java 21 only, where plain-XX:+UseZGCstill runs the older non-generational mode.-Xmsset to the same value as-Xmx, plus-XX:+AlwaysPreTouch, claims the whole heap at startup. Oracle recommends this pairing when low latency is the reason you run ZGC, because growing and shrinking the heap while the server runs can hurt latency (Oracle ZGC guide).-XX:+DisableExplicitGCmakes the JVM ignoreSystem.gc()calls, so a plugin or mod cannot start a collection on its own.
Side by Side
| G1GC (Aikar's) | ZGC | |
|---|---|---|
| Pauses | Stop-the-world young and mixed collections, 200 ms pause goal by default | Under a millisecond, independent of heap size |
| Throughput | Aims for high throughput while meeting its pause goal | Some throughput cost for the concurrent work |
| Memory | Works well on modest heaps | Needs headroom; Oracle: "the more memory you give to ZGC the better" |
| Tuning | Aikar's flags, many options | A handful of flags |
| Java | Every version Minecraft uses | Java 21 with -XX:+ZGenerational, Java 25 as is |
Sources: the Oracle G1 guide and the Oracle ZGC guide. What the difference means in tick times on your server depends on your heap, plugins and players, so measure it (see the end of this post).
When to Use Which
Use G1GC (Aikar's) when:
- Server has 4 to 12 GB RAM
- You want proven, well-documented performance
- Running on limited CPU resources
- Classic setup that works reliably
Use ZGC when:
- Server has 12+ GB RAM
- You see GC-related lag spikes on G1GC
- Running a heavy modpack with many objects
- High player count (50+) where pauses are noticeable
- You have spare CPU and memory
If you are sizing a server for ZGC, count the heap plus headroom: a 12GB heap fits a 16GB plan. On Space-Node that is MC Special 3, €14.40 a month on Standard or €27.99 on Premium performance hosting, which in the Netherlands, Germany, Poland and Canada runs on Ryzen 9 9950X nodes with 6 to 8 vCores of shared CPU under fair use. You paste the flags above into the Startup tab yourself.
How to Switch
Change your start script from:
-XX:+UseG1GC [Aikar's flags...]
To this on Java 25:
-XX:+UseZGC
Or this on Java 21:
-XX:+UseZGC -XX:+ZGenerational
Remove all G1GC-specific flags when switching to ZGC. That includes -XX:+UnlockExperimentalVMOptions, which Aikar's set only needs for its experimental G1 options. Set -Xms equal to -Xmx so the heap does not resize. On Java 21, keep -XX:+ZGenerational: generational ZGC collects young objects more often (JEP 439), and most of what Minecraft allocates is short-lived (PaperMC docs). On Java 25, delete -XX:+ZGenerational if an older guide added it, because it only prints a warning there.
What About Shenandoah?
Shenandoah, developed by Red Hat, is a third low-pause collector worth knowing about. It targets the same problem as ZGC, concurrent collection with minimal stop-the-world pauses, but with a slightly different tradeoff profile.
| Feature | ZGC | Shenandoah |
|---|---|---|
| Developer | Oracle | Red Hat |
| Pause times | Sub-millisecond | Low millisecond |
| JDK availability | All major JDKs (17+) | OpenJDK, Red Hat builds |
| Best for | Large heaps (10 GB+) | Medium to large heaps |
In practice, ZGC is the better default for a Minecraft server: it is available on every major JDK, has lower pause times, and is the collector most hosting panels and guides are tuned around. Reach for Shenandoah only if your JDK distribution does not ship ZGC, or you are already standardized on a Red Hat-based build. The flag is -XX:+UseShenandoahGC, and like ZGC, do not mix it with G1GC flags.
Measure, Do Not Guess
Whatever you pick, measure it. Run spark under real load and write down, for each collector: players online, the longest GC pause from /spark gc, how often ticks go over 50 ms (/spark tickmonitor --threshold-tick 50 reports GC activity alongside), the median and 95th percentile MSPT from /spark tps, and the process memory your panel shows. If Aikar's flags already give you flat ticks, ZGC will not magically add TPS, GC tuning is only worth doing when GC is actually your bottleneck. For a deeper look at flag tuning beyond the collector choice itself, see Aikar's flags and JVM arguments.
No collector fixes weak hardware. GC tuning helps at the margins, fast single-thread CPU and enough RAM do the heavy lifting. A 16GB modpack on a slow shared core will stutter no matter which collector you choose. If you have already tuned flags and are still hunting for headroom, GraalVM is worth a look as a JIT-level alternative.
FAQ
Is ZGC better than Shenandoah for Minecraft? For most servers, yes, mainly because it ships in more JDK builds and most Minecraft GC guides cover it. Both avoid G1GC's longer stop-the-world pauses on big heaps.
Should I switch from Aikar's flags? Aikar's flags are tuned for G1GC and remain the best default under about 12GB. If you allocate 12GB or more, ZGC (or Shenandoah) with the flags above is worth testing.
Do I still need -XX:+ZGenerational? Only on Java 21, which Minecraft 1.20.5 to 1.21.11 use. On Java 25, which Minecraft 26.1 to 26.3 require, generational ZGC is the only ZGC mode and the flag just prints an obsolete option warning. Remove it there.
Does GraalVM ship with ZGC? Yes, GraalVM ships ZGC. Shenandoah is available in standard OpenJDK builds instead.
Legal Notice
Legal Notice & Disclaimer: This article constitutes an independent, factual comparative review and critical analysis for educational purposes only. Space-Node is not affiliated with, endorsed by, or sponsored by any hosting provider mentioned herein. All brand names, logos, and trademarks referenced are the registered intellectual property of their respective owners and are used solely for identification and factual reference.
Fair Use & Review Rights: This review is protected commentary, comparison, and criticism. It is based on publicly available information, official pages where available, published documentation, and general hosting engineering analysis. Where hands-on testing is not explicitly stated in the article, no private benchmark or internal infrastructure access is implied. This constitutes lawful comparative review and criticism protected under fair use doctrine.
Factual Accuracy: Specific plan claims are based on public information available at the time of writing. Specifications, pricing, and service features can change, so readers should verify current details on the provider's official website before purchasing. We make no false or defamatory statements; criticism is limited to documented facts, clearly labeled opinion, or general hosting guidance.
No Consumer Confusion: This article makes clear that Space-Node offers distinct, independently-developed hosting infrastructure. We explicitly differentiate our services, pricing, and technical specifications. No reader could reasonably be confused about service provider identity.
Right to Comparative Advertising: Space-Node reserves the right to publish factual comparative information about competing services. This is a recognized right in consumer protection law and advertising standards. Accurate comparative reviews cannot constitute trademark violation, defamation, or unfair competition.
Limitation of Liability: Space-Node makes no warranty regarding third-party services reviewed. Readers are responsible for verifying information independently before purchasing. Space-Node disclaims liability for third-party service changes, outages, or policy modifications.
Space-Node Services: For Space-Node's own managed hosting solutions, visit Minecraft hosting or VPS hosting.