Skip to main content
← All Guides
Performance · 5 min read

What Is GC and Why Does It Lag Your Server

Learn what garbage collection is, why it causes lag spikes on Minecraft servers, and how to minimize GC pauses.

What Is Garbage Collection?

Minecraft servers run on the Java Virtual Machine (JVM). Java manages memory automatically through a process called garbage collection (GC). When objects in memory are no longer needed, the GC identifies and frees them. This is convenient for developers but creates a problem for servers: GC pauses. During a GC pause, the server thread stops completely, causing a visible lag spike. Understanding garbage collection minecraft server lag is essential for running a smooth server.

Why GC Pauses Happen

The JVM allocates objects on the heap. Minecraft creates millions of short-lived objects every second: packet data, chunk section copies, entity position vectors, pathfinding nodes, and more. As the heap fills up, the GC must run to reclaim space. A "minor" GC collects short-lived objects and typically takes 5 to 20 ms. A "major" or "full" GC collects everything and can take 100 to 500 ms or more. A 200 ms pause means 4 ticks are skipped, which players feel as a stutter.

How to Detect GC Lag

Use Spark to monitor GC activity:

/spark health

Look at the GC section. If you see frequent collections or any collection taking more than 50 ms, garbage collection minecraft server lag is likely contributing to your TPS drops.

You can also add JVM flags to log GC activity:

-verbose:gc -Xlog:gc*:file=gc.log:time

This writes every GC event to a log file with timestamps. Review it after a play session to correlate lag reports with GC pauses.

Common Causes of Excessive GC

  • Insufficient heap: If -Xmx is too low, the GC runs constantly because it never has enough free space. See our RAM calculator to determine the right allocation.
  • Too much heap: Paradoxically, allocating far more RAM than needed (e.g., 32 GB for a 10-player server) means major GC pauses take longer because the collector has more memory to scan.
  • Wrong GC algorithm: The default GC in older Java versions is not optimized for Minecraft's allocation patterns. See our GC comparison guide.
  • Memory leaks: Plugins that hold references to objects indefinitely prevent the GC from reclaiming them, slowly filling the heap.
  • Chunk churn: Rapidly loading and unloading chunks creates large amounts of garbage. Pregenerating and optimizing chunk loading reduces this.

Minimizing GC Pauses

Right-Size Your Heap

Set -Xms and -Xmx to the same value. This prevents the JVM from resizing the heap at runtime, which triggers full GC pauses. For a 20-player server, 4 to 6 GB is typical. For 50+, 8 to 14 GB. Check our RAM guides for 4 GB, 8 GB, and 16 GB servers.

Use Optimized JVM Flags

Aikar's flags tune G1GC specifically for Minecraft's memory patterns. They adjust region size, pause targets, and promotion thresholds. See our JVM flags guide for the complete set.

Consider a Low-Pause Collector

For servers with 10+ GB of heap, ZGC and Shenandoah offer sub-millisecond pauses at the cost of slightly higher CPU usage. This eliminates garbage collection minecraft server lag almost entirely. Our GC comparison guide covers when to switch.

Need a server built for performance? Astroworld Hosting runs NVMe SSDs with optimized Paper configs on every plan.

Key Takeaways

  • GC pauses are the primary cause of periodic lag spikes on Java servers.
  • Monitor with Spark and GC logging.
  • Right-size your heap, not too small, not too large.
  • Use tuned JVM flags for your chosen collector.
  • Address garbage collection minecraft server lag before blaming plugins or hardware.

Related Tools & Resources

🔧

Minecraft Tools

Calculators, generators & server tools

🧱

Item Database

Browse all Minecraft items, stats & recipes

⚒️

Crafting Recipes

Visual crafting guides for every recipe