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 shows | What it means | Go to |
|---|---|---|
java.lang.OutOfMemoryError: Java heap space | The heap filled up and garbage collection couldn't free enough | Step 2 |
java.lang.OutOfMemoryError: GC overhead limit exceeded | Same problem, caught earlier: Java was spending almost all its time collecting garbage and getting almost nothing back | Step 2 |
| The log stops mid-line, no error, no crash report. The panel says the server stopped or was killed | The OS or container killed Java for using more memory than the machine or container allows | Step 3 |
OutOfMemoryError: Metaspace | The space for loaded classes ran out, almost always because someone set -XX:MaxMetaspaceSize too low | Step 4 |
OutOfMemoryError: unable to create native thread | Not a RAM problem: a thread or process limit was hit, usually by a mod or plugin starting threads in a loop | Step 4 |
Cannot reserve ... bytes of direct buffer memory | Off-heap network buffers ran out, not the heap | Step 4 |
Could not reserve enough space for object heap or Invalid maximum heap size at startup | Java never started: the -Xmx value is wrong or too big for that Java | Step 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:
- 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
modsfolder (players don't need it). - Run
/spark health show --memorynow and again an hour later. If "used" after GC keeps rising with the same players online, it's a leak. - 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. - If the summary isn't clear,
/spark heapdump --compress gzipwrites a full.hprofsnapshot to disk. Open it with Eclipse Memory Analyzer and use the "Leak Suspects" report. - No spark? Add
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=heapdump.hprofto 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 peak | about 530 MiB |
| Whole Java process at peak | 4,362 MiB of 4,506 MiB |
| OOM kills | 0 |
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:
- On your own Linux box:
journalctl -k | grep -i -E "out of memory|killed process"(ordmesg -T) shows a line likeOut of memory: Killed process 1234 (java). - In Docker:
docker inspect --format '{{.State.OOMKilled}}' <container>printstrue. - On a hosting panel: you usually can't see the kernel log. A stop with no error at the end of the log, right when memory in the panel was at its limit, is the sign. Ask your host if they can see an OOM kill.
How to fix it:
- Give the heap less than the full amount. The Paper project's guide to Aikar's flags says to set
-Xmsand-Xmxabout 1,000 to 1,500 MB below the RAM you have, e.g. 6,500 MB on an 8 GB machine. On a small hosted plan, leave at least 600 MB outside the heap for Paper and more for modpacks. - If you use Aikar's flags, remember they include
-XX:+AlwaysPreTouchand set-Xmsequal to-Xmx, so Java claims the whole heap the moment it starts. A heap that's too big then fails right away instead of hours later. - On your own PC, the game client, browser and Discord share the same RAM. A 16 GB PC running the client and a server can't give the server 12 GB.
- If the heap you can fit is smaller than the pack needs, that's Step 2's "undersized" case: you need a bigger machine or plan, not a bigger
-Xmx.
Step 4: the other OutOfMemoryErrors
- Metaspace. Modern Java doesn't cap metaspace unless you tell it to. If your start command has
-XX:MaxMetaspaceSize=..., raise it (512mis plenty for most packs) or remove it. Old guides for Java 8 often added it. - Unable to create native thread. Despite the name, this is a thread or process count limit (containers set one too), not free RAM. Look in the crash report for hundreds of threads with the same name: the mod or plugin that owns them is starting threads without stopping them. Update or remove it.
- Direct buffer memory. Network code (Netty) uses memory outside the heap for buffers. By default its limit follows the heap size. It usually shows up with proxy or networking mods and plugins, or under connection floods. Update those first. Raising
-Xmxwon't help, and it can push you into Step 3.
Step 5: Java won't start because of the heap setting
Invalid maximum heap size: -Xmx4GB: the unit is wrong. Java takesk,morg, so use-Xmx4Gor-Xmx4096M, neverGBorMB.Could not reserve enough space for 4194304KB object heap: usually a 32-bit Java, which can't hold a heap of more than about 1.5 GB. Runjava -version. It should say64-Bit Server VM. If it doesn't, install a 64-bit Java of the right version (see which Java version your Minecraft server needs).- On a hosting panel, don't paste your own
-Xmxinto a startup field if the host already sets the heap. Two-Xmxvalues on one line can fight, and the one that wins may be bigger than the plan.
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:
- Vanilla or Paper with a few friends: 3 to 4 GB.
- Light modpacks (Fabric, a few dozen mods): 4 to 6 GB.
- Big kitchen-sink packs: 8 GB or more. ATM10 is a good example, see how much RAM an ATM10 server needs.
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.