Minecraft

Fix Minecraft "java.lang.OutOfMemoryError: Java heap space"

java.lang.OutOfMemoryError: Java heap spaceGC overhead limit exceededServer crashed: out of memory
6 min read Updated 14 June 2026 ESAGAMES Team

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.

What it means

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

  1. Raise -Xmx to a sensible value for your pack — but leave OS headroom.
  2. Make sure the machine or plan actually has that much RAM.
  3. Use a tuned flag set (Aikar's flags) for better garbage collection.
  4. Find and remove any leaking mod or plugin.
  5. 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.

RAM that scales with you

Our Minecraft hosting runs on fast CPUs with the RAM your modpack needs — protected and online in minutes.

Minecraft hosting
FAQ

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.

Knowledge base

Related articles

Skip the troubleshooting

Managed, protected hosting in Frankfurt — we handle the Linux, the network and the DDoS so you don't have to.

Payments Secure checkout with cards, banking apps and digital wallets.

Choose the payment flow that fits your stack and region without leaving the platform.

Pay by Zen Visa Mastercard Paysafecard PaysafeCash Skrill Trustly Bancontact UnionPay iDeal WebMoney