Skip to content
Minecraft

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

java.lang.OutOfMemoryError: Java heap spaceGC overhead limit exceededServer crashed: out of memory
8 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

How much -Xmx to set depends on what you're running:

SetupPlayersRAM to allocate (-Xmx)
Vanilla / Paper2 – 102 – 4 GB
Small modpack / plugins5 – 204 – 6 GB
Medium modpack10 – 206 – 8 GB
Big modpack (All the Mods, RLCraft)5 – 208 – 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

  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.

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.

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.

Why is my -Xmx setting being ignored?

The most common reason is a 32-bit Java install, which can't use more than about 4 GB regardless of the flag. Install 64-bit Java. On panels, also make sure the panel isn't overriding your start command with its own lower memory limit.

What does "GC overhead limit exceeded" mean?

It means Java's garbage collector is spending nearly all its time reclaiming tiny amounts of memory — effectively the same out-of-memory situation, just caught slightly earlier. The fixes are identical: more RAM, tuned flags, or removing whatever is over-consuming memory.

Should I allocate all my server's RAM to Minecraft to avoid this?

No — always leave 1-2 GB for the operating system and the JVM's own overhead. Allocating everything can trigger the OS out-of-memory killer, which crashes the server just as hard as the Java heap error.

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