The "OutOfMemoryError: Java heap space" crash means your Minecraft server tried to use more RAM than it was allowed and Java gave up. Here is what causes it and how to fix it — properly, not just by throwing RAM at it.
Quick answer
"OutOfMemoryError: Java heap space" means the server needed more RAM than its -Xmx limit allowed, so Java crashed it. Raise -Xmx (and match -Xms) if the machine has free memory, and reduce the demand: lower view-distance, pre-generate the world, and update or remove leaky plugins and mods. More RAM alone often only delays the next crash.
Java runs with a fixed maximum heap (set by -Xmx). When the world, entities, chunks and plugins need more than that limit, Java throws OutOfMemoryError and the server crashes. The fix is more RAM, fewer demands, or both.
Cause 1: the RAM limit is too low
Your server starts with a maximum-memory flag, -Xmx. If it is too low for your modpack or player count, you will run out. Raise it in your start command (see how to allocate more RAM):
java -Xms4G -Xmx4G -jar server.jar noguiHow much -Xmx to set depends on what you're running:
| Setup | Players | RAM to allocate (-Xmx) |
|---|---|---|
| Vanilla / Paper | 2 – 10 | 2 – 4 GB |
| Small modpack / plugins | 5 – 20 | 4 – 6 GB |
| Medium modpack | 10 – 20 | 6 – 8 GB |
| Big modpack (All the Mods, RLCraft) | 5 – 20 | 8 – 10 GB+ |
Cause 2: you are giving Java more than the machine has
You cannot allocate more RAM than the machine physically has — and you must leave headroom for the OS. On a box with 8 GB, do not set -Xmx8G; leave 1–2 GB for the system. On shared hosting, your plan's RAM is the ceiling.
Cause 3: a memory leak from a mod or plugin
If memory climbs steadily until it crashes every few hours no matter how much you give it, a misbehaving plugin or mod is likely leaking. Narrow it down by reviewing recent additions and your crash report, then remove or update the culprit.
Cause 4: too much going on
Huge render/view distance, thousands of loaded entities, or massive redstone and farms all eat RAM. Reduce view-distance, limit entities and pre-generate your world — the same tuning that fixes low TPS and general lag.
The fix, in order
- Raise
-Xmxto a sensible value for your pack — but leave OS headroom. - Make sure the machine or plan actually has that much RAM.
- Use a tuned flag set (Aikar's flags) for better garbage collection.
- Find and remove any leaking mod or plugin.
- Lower view-distance and entity counts; pre-generate the world.
More RAM buys headroom, but a leak or a runaway farm will eat any amount you give it. Fix the cause, not just the number.
Cause 5: 32-bit Java capping your heap
A 32-bit Java install can't address more than around 4 GB no matter what -Xmx you set, so a large value is silently ignored and you keep running out. Confirm you're running 64-bit Java, especially on older self-hosted setups, so your allocation actually applies.
Cause 6: the wrong Java version for your server jar
Newer Minecraft versions require newer Java, and a mismatch can cause instability and memory-related crashes on top of outright startup failures. Make sure your Java version matches what your server jar and modpack expect — related to the unsupported class version error.
How to prevent OutOfMemoryError crashes
- Match allocated RAM to your pack with a little headroom, and revisit it when you add mods or players.
- Use Aikar's flags for smoother garbage collection.
- Pre-generate the world to avoid chunk-loading spikes during play.
- Test new plugins/mods on a copy first, watching memory over a few hours for leaks.
- Keep the server on 64-bit Java that matches your Minecraft version.
Related errors
For the RAM allocation how-to, see how to allocate more RAM to a Minecraft server. If low TPS rather than RAM is the real problem, see "Can't keep up". Setting a server up from scratch? See how to make a Minecraft server.
Minecraft is a trademark of Mojang Synergies AB / Microsoft. ESAGAMES is an independent hosting provider, not affiliated with or endorsed by Mojang or Microsoft.