Fix Minecraft "java.lang.OutOfMemoryError: Java heap space"
java.lang.OutOfMemoryError: Java heap spaceGC overhead limit exceededServer crashed: out of memoryThe "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.
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 nogui
A rough guide: vanilla/Paper with a few players is happy on 2–4 GB; medium modpacks want 4–6 GB; big modpacks (All the Mods, RLCraft) often need 8–10 GB or more.
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.
Minecraft is a trademark of Mojang Synergies AB / Microsoft. ESAGAMES is an independent hosting provider, not affiliated with or endorsed by Mojang or Microsoft.
RAM that scales with you
Our Minecraft hosting runs on fast CPUs with the RAM your modpack needs — protected and online in minutes.
Frequently asked questions
How much RAM does a Minecraft server need?
Vanilla or Paper with a handful of players runs on 2–4 GB. Medium modpacks want 4–6 GB; large modpacks like All the Mods or RLCraft often need 8–10 GB or more.
Does giving more RAM always fix OutOfMemoryError?
No. If a plugin or mod is leaking memory it will eventually exhaust any amount you give it. If memory climbs steadily until a crash, find the leaking add-on instead.
What are Aikar's flags?
A well-known set of JVM startup flags that tune Java's garbage collector for Minecraft, giving smoother performance and fewer memory spikes than the defaults.
Related articles
How to Allocate More RAM to a Minecraft Server
Give your Minecraft server more RAM — the -Xmx/-Xms flags, doing it in a panel, and how much to allocate.
Read fix Game ServersFix AMX Mod X "Couldn't load library" / Plugin Failed in CS 1.6
AMXX plugin stuck on "bad load", "couldn't load library" or "failed"? The real causes and the exact fix.
Read fix Game ServersFix FiveM "Couldn't load resource" / Failed to Start
A FiveM resource won't start or throws "couldn't load resource"? Here are the real causes and fixes.
Read fix