CYBER DEAL UP TO -40% FIRST YEAR
Glossary background texture

Garbage Collection (GC)

What Is Garbage Collection (GC) in Minecraft Servers?

Garbage collection (GC) is how Java automatically cleans up memory your Minecraft server doesn’t need anymore. When chunks are unloaded, mobs die, items despawn or plugins finish their work, the data behind them becomes “junk” in RAM.

Server memory before cleanup

Garbage collection is the system that finds that trash and throws it out so there’s room for new chunks, mobs and plugin tasks.

Why garbage collection is important?

When your server is running, Java is constantly creating little bits of data in the background. A new mob spawns? That’s data. A plugin runs a command? More data. Players run off in different directions and load new chunks? Even more data.

If the garbage collector doesn’t run, your RAM fills up until the server crashes. If it runs in a bad way, your players feel it as lag spikes: the server suddenly freezes for a moment while Java cleans.

"Out of memory" error

So GC is a trade-off:

You need it to avoid running out of memory but while Java is checking and deleting that old data, your server thread can pause for a moment. If there’s a lot to clean, that pause is long enough that players feel it as a little freeze or lag spike.

Garbage collection pauses to cleanup "junk" from memory

By default, Java’s GC isn’t tuned for Minecraft’s constant stream of chunks, entities and plugin activity. That’s why large, infrequent cleanups can cause big, obvious freezes.

Once the cleanup is done, the freed space becomes available RAM for new objects.

Server memory after cleanup

Aikar's Flags: Improved Garbage Collection for Paper Servers

If you run a Paper server you can make Java’s garbage collection behave better on Minecraft servers by using Aikar's flags.

Instead of a few big cleanups that cause noticeable freezes, Aikar’s Flags tune the garbage collector to run smaller, more frequent cleanups, use multiple CPU cores, and prepare memory more efficiently at startup.

Don't miss out

CYBER DEAL
UP TO -40%

Host a Minecraft Server today with the best Cyber deal discount

  • -40% First Month
  • -10% First Quarter
  • -40% First Year