Client Area
Guide

How to Fix the Minecraft Out of Memory Error (java.lang.OutOfMemoryError)

Minecraft··3 min read
Minecraft: Java Edition server hosting

Seeing java.lang.OutOfMemoryError: Java heap space in your console, or the message "Minecraft has run out of memory" on your screen? It means Java ran out of the RAM it was allowed to use, so the game or server crashes. The good news: the Minecraft out of memory error is almost always fixable. Here is what causes it and how to fix it for good.

What java.lang.OutOfMemoryError actually means

Java apps run inside a fixed memory budget called the heap, set with the -Xmx (maximum) flag. When Minecraft needs more than that budget — too many chunks, entities, a heavy modpack or a memory leak — Java throws java.lang.OutOfMemoryError: Java heap space and stops. It is not a corrupted world or a virus; it is simply "give me more room, or use less."

Server-side or client-side?

Both can run out of memory. On a server you will see OutOfMemoryError in the console and players get disconnected; on the client the game freezes and you get the "Minecraft has run out of memory" crash screen. The fixes below apply to both — the difference is only where you set the RAM.

1. Allocate more RAM (the main fix)

Raise the maximum heap with -Xmx. A self-hosted server start line looks like:

java -Xms4G -Xmx4G -jar server.jar nogui

Set -Xms (starting) and -Xmx (maximum) to the same value to avoid resizing pauses. On a rented GGameHost Minecraft server you do not edit flags by hand — pick a plan with more RAM, or raise it one click in the panel, and the startup memory is set for you.

2. Don't over-allocate

Giving Java all your system RAM backfires: the OS and Java's own overhead need headroom, and huge heaps cause long garbage-collection pauses. Leave ~1–2 GB free for the system. On your own PC, never set -Xmx to your full installed RAM.

3. Use Aikar's flags

The community-standard Aikar's flags tune Java's G1 garbage collector for Minecraft, smoothing memory use and preventing many OOM spikes on modded and busy servers. Generate them at flags.sh and add them to your start command. On GGameHost, optimized JVM flags are applied for you.

4. Match RAM to your setup

  • Vanilla, 2–5 players: 2–3 GB
  • Plugins / 5–10 players: 3–4 GB
  • Forge or Fabric modpacks: 6–8 GB+
  • Large "kitchen-sink" packs / big networks: 8–12 GB+

If you constantly hit OutOfMemoryError at 4 GB with a modpack, that is the pack telling you it needs more — upgrade rather than fight it.

5. Find memory leaks (mods & plugins)

A single leaking mod or plugin can exhaust any amount of RAM over time — the tell-tale sign is memory that climbs for hours until it crashes. Use /spark profiler or a heap dump to find the culprit, update everything to current versions, and remove what you do not use.

6. Reduce chunk and entity load

Lower view-distance and simulation-distance in server.properties (8 and 6 are sane), pre-generate the world so it is not carving new chunks live, and clear giant mob farms or dropped-item pile-ups. Less to keep in memory means fewer OOM crashes and better TPS — see our reduce server lag guide.

7. Use a current 64-bit Java

32-bit Java caps the heap near 1.5 GB and OOMs early — always run 64-bit Java. Modern Minecraft needs Java 17+ (21 for the latest versions); an outdated Java can both leak and refuse large heaps. Managed hosts keep the correct Java version for you.

When to upgrade your host

If you have tuned flags, distances and mods and still see java.lang.OutOfMemoryError, you have simply outgrown your RAM. On GGameHost you raise RAM in one click on high-clock AMD Ryzen + NVMe hardware — no reinstall, no editing flags, no more out-of-memory crashes.

Get a Minecraft server with the right RAM →

Related guides

Share:Twitter / XFacebookRedditWhatsApp

Ready to play?

Deploy your server in under 60 seconds — 7-day money-back guarantee.

Browse games