java.lang.OutOfMemoryError: Java heap space
OutOfMemoryError: Java heap space means the JVM exhausted the memory you allocated to it. On Minecraft servers, this is almost always a heap-sizing problem: the -Xmx flag (max heap) is set lower than the modpack genuinely needs at peak load.
Fastest path: paste your crash report into the Crash Doctor — it identifies this pattern and 40+ others automatically. No signup.
How to fix it
- 1
Match heap size to the modpack
The rule: heap = plan - 4 GB (the 4 GB covers JVM metaspace, native code from Sodium / spark, and OS overhead inside the container). Concrete values: Vanilla and Paper need 2 GB heap (4 GB plan). Light modded (Fabric Performance, 50-150 mods): 4-6 GB heap. RLCraft: 6-8 GB heap (10-12 GB plan). Heavy modpacks like ATM10, Better MC BMC4, and ZOMBIEMANIA need 12 GB heap on a 16 GB plan — 8 GB plans OOM during the first night-time mob spawn cycle. Massive 350+ mod packs like Cisco's Fantasy run on 16 GB heap (20 GB plan).
- 2
Account for non-heap memory
The container or VM running your server needs ~3-4 GB extra on top of -Xmx for JVM metaspace, native code (Sodium, spark, mod natives), and OS overhead. A 16 GB plan with a 14 GB heap will OOM-kill the container, not just throw OOM in Java.
- 3
Lower simulation and view distance before adding more RAM
view-distance=8 and simulation-distance=6 in server.properties cut tick memory by 50-70% with minimal player impact. Try this first — it's free.
- 4
Disable spark / OptiFine memory leaks if you're on those
Older spark builds leaked profile data; OptiFine has a known unloaded-chunk reference leak on 1.12. Update or remove if the heap climbs monotonically with no GC recovery.
Alternative causes
These can produce the same error message — worth ruling out if the steps above don't resolve it.
Heap is sized fine but a single mod leaks
If your heap usage climbs over hours and never drops after garbage collection, one mod is holding references. Run a spark heap-dump and look for the biggest retained-size class. Usually it's a chunk-cache or entity-tracker.
JVM flags missing — Aikar's recommended GC
Default G1 GC isn't tuned for MC. Aikar's flags (https://docs.papermc.io/paper/aikars-flags) cut pause times and recover memory more aggressively, often turning a borderline-OOM server stable.
Frequently asked
How much RAM does ATM10 actually need?
ATM10 needs a 12 GB heap and a 16 GB plan. The formula is heap = plan - 4 GB (the 4 GB covers JVM metaspace, native code from Sodium and spark, plus OS overhead). 8 GB plans run out of memory during the first night-time mob spawn cycle. Better MC BMC4 and ZOMBIEMANIA size the same way. ATM9 is a little lighter — 10 GB heap on a 14 GB plan covers it.
Will adding more RAM fix tick lag?
No. RAM size doesn't affect tick speed — that's CPU- and mod-bound. More RAM only helps if you're actually OOMing or GC-thrashing. Use spark to confirm before upgrading the plan.
Why does the server OOM 20 minutes after boot, not at startup?
Modpacks load mods at boot but generate the world (and load chunks, spawn mobs, register entities) gradually. Memory peaks 15-30 minutes in, after the first set of chunks is fully populated. Size for peak, not boot.
Want this auto-fixed on your server?
CoalHosting's Minecraft hosting runs the same pattern database against every crash and applies the known fix before your players notice. Free crash diagnosis works on any server, hosted or not.
Related crashes
Watchdog tick timeout (single server tick took)
Fix Minecraft server watchdog crashes — a tick took longer than 60s and the server killed itself. Usually a he…
No space left on device (Minecraft IOException)
Fix the Minecraft server 'No space left on device' crash — the container ran out of disk. Find what's eating s…
java.lang.UnsupportedClassVersionError
Fix the Minecraft server UnsupportedClassVersionError crash — the Java runtime is newer or older than the mod …
Last reviewed 2026-06-05. If a step is wrong or out of date, tell us — we'll fix the article and the auto-pattern at the same time.