PACKYARDStart your server

Minecraft Server Out of Memory? Fix Each Crash Type (2026)

Published

Short answer: "Out of memory" on a Minecraft server means one of two opposite things. Either the Java heap is too small for what the server is doing (you get java.lang.OutOfMemoryError in the log), or the heap is too big for the machine and the operating system kills Java from outside (the log just stops, with no error). The first is fixed with more heap or by finding a leak. The second is fixed by giving Java less heap, so there's room for everything that isn't heap. Read the end of your log first to see which one you have.

Most guides only cover the first case and tell you to raise -Xmx. We hit the second case on our own servers, measured it, and fixed it, so this guide covers both, with the numbers.

Step 1: work out which memory crash you have

Open logs/latest.log (and the newest file in crash-reports/, if there is one) and look at the last lines before the server died.

What the log showsWhat it meansGo to
java.lang.OutOfMemoryError: Java heap spaceThe heap filled up and garbage collection couldn't free enoughStep 2
java.lang.OutOfMemoryError: GC overhead limit exceededSame problem, caught earlier: Java was spending almost all its time collecting garbage and getting almost nothing backStep 2
The log stops mid-line, no error, no crash report. The panel says the server stopped or was killedThe OS or container killed Java for using more memory than the machine or container allowsStep 3
OutOfMemoryError: MetaspaceThe space for loaded classes ran out, almost always because someone set -XX:MaxMetaspaceSize too lowStep 4
OutOfMemoryError: unable to create native threadNot a RAM problem: a thread or process limit was hit, usually by a mod or plugin starting threads in a loopStep 4
Cannot reserve ... bytes of direct buffer memoryOff-heap network buffers ran out, not the heapStep 4
Could not reserve enough space for object heap or Invalid maximum heap size at startupJava never started: the -Xmx value is wrong or too big for that JavaStep 5

One more trap: in a Forge or NeoForge crash report, the first exception isn't always the cause. Scroll to the last Caused by: line. If it says OutOfMemoryError, memory is the problem. If it names a mod's class, that mod crashed, and the memory is a red herring.

Step 2: "Java heap space" and "GC overhead limit exceeded"

The heap is the memory Java uses for the world, chunks, entities and mod data. It's capped by -Xmx. When it's full, the server crashes. There are two reasons it fills up.

The server is undersized. Memory climbs when people explore or join, then drops back after garbage collection, but the peaks keep touching the ceiling. That's normal use outgrowing the plan. Typical triggers: a modpack on less than its pack author's minimum, more players than planned, or a big pre-generation run on a small heap. Check the size against the pack in our modpack server RAM guide or the RAM calculator, then raise -Xmx (see Step 3 for how far).

Something is leaking. Memory after each garbage collection keeps climbing over hours, whatever the players do, until the crash. More RAM only delays it. To find it:

  1. Get spark. Paper 1.21 and newer already have it built in. On Fabric, Forge and NeoForge, add the spark mod to the server's mods folder (players don't need it).
  2. Run /spark health show --memory now and again an hour later. If "used" after GC keeps rising with the same players online, it's a leak.
  3. Run /spark heapsummary. It uploads a summary of which classes hold the most memory. A mod's or plugin's package name near the top (e.g. com.example.somemod...) points at the culprit.
  4. If the summary isn't clear, /spark heapdump --compress gzip writes a full .hprof snapshot to disk. Open it with Eclipse Memory Analyzer and use the "Leak Suspects" report.
  5. No spark? Add -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heapdump.hprof to the start command, and Java writes a dump at the moment of the next crash. A dump is about the size of the heap, so check your disk space first.

Then update or remove that mod or plugin. If you need the server running in the meantime, a daily restart is a stopgap, not a fix.

Things that look like leaks but aren't: thousands of dropped items or mobs in loaded chunks, chunk loaders keeping big areas loaded, and huge storage systems. /spark profiler and the entity counts in /spark health show those.

Step 3: the server is killed with no error (the OS killed it)

This is the case most guides miss, and raising -Xmx makes it worse.

Java needs memory outside the heap: loaded classes (metaspace), every thread's stack, network buffers, the garbage collector's own bookkeeping, and the JIT compiler. A host gives your server a fixed amount of RAM (a container limit on a hosting panel, or simply the machine's RAM at home). If heap plus all of that goes over the limit, Linux's out-of-memory killer ends the process at once. Java gets no chance to write an error, so the log just stops.

What we measured. One of our own early 4 GB Paper servers was started with the heap at 95% of its container (-XX:MaxRAMPercentage=95), which is a common default in hosting panels. That gave a 4,280 MiB heap in a 4,506 MiB container, leaving about 225 MiB for everything else. The server was killed by the OS twice. We reran the same 4 GB server type on a test node with the heap at 85% (3,830 MiB) and ran a worst-case load, a Chunky pre-generation at radius 6,000:

Result
Memory outside the heap, at peakabout 530 MiB
Whole Java process at peak4,362 MiB of 4,506 MiB
OOM kills0

So a plain Paper server needed about half a gigabyte beyond its heap under heavy load. Modded servers load far more classes, so plan for more: we budget about 900 MiB outside the heap for modpacks, which is an estimate, not a measurement.

How to confirm it was the OS:

How to fix it:

Step 4: the other OutOfMemoryErrors

Step 5: Java won't start because of the heap setting

How much RAM a server actually needs

Allocate for the heaviest moment, not the idle one. A server that idles at 2 GB can need twice that while several people fly into new terrain. Rough starting points:

Then remember the plan's RAM has to cover the heap and the half gigabyte or more outside it.

Run it on Packyard

On Packyard, Minecraft hosting is $1.50 per GB of RAM per month, with a $5 minimum that covers 3 GB (USD, plus applicable taxes). The panel has an Assistant tab: press Diagnose, and it reads your newest crash report and log and tells you in plain words what most likely went wrong and what to try. Your friends join at an address that stays the same. Open to the US and Canada (outside Quebec).

Start a Minecraft server on Packyard, 3 GB for $5 a month

Minecraft is a trademark of Mojang/Microsoft. Packyard is not affiliated with Mojang, Microsoft or PaperMC.

FAQ

Why does my Minecraft server say "Java heap space"?

The heap, the memory Java uses for the world and mods, filled up and garbage collection couldn't free enough. Either the server needs more heap for its pack and players, or a mod or plugin is leaking. /spark heapsummary tells you which.

My server stops with no error at all. Is that out of memory?

Often, yes. When Java's total memory goes over the machine's or container's limit, the operating system kills it instantly, so nothing gets written. The fix is a smaller heap with more room outside it, not a bigger one.

How much RAM should I leave outside the heap?

Paper's guide says 1,000 to 1,500 MB on your own machine. In our own measurements, a 4 GB Paper server used about 530 MiB outside its heap under heavy load. Modpacks need more.

Will more RAM fix out-of-memory crashes?

Only if the server is truly undersized. If memory after garbage collection keeps climbing over hours, a mod or plugin is leaking, and more RAM only delays the crash.

What's the difference between -Xms and -Xmx?

-Xmx is the most heap Java may use. -Xms is how much it reserves at the start. Paper recommends setting both to the same value, and both must fit inside your RAM with room left over.

Why does "GC overhead limit exceeded" happen?

Java was spending nearly all its time collecting garbage and freeing almost nothing. It's the same root cause as "Java heap space", caught a little earlier, so treat it the same way.

More guides and posts on the Packyard blog.