Skip to main content
← All Guides
Troubleshooting · 5 min read

Fix 'Out of Memory' Error on Minecraft Servers

Resolve java.lang.OutOfMemoryError on Minecraft servers, diagnose memory leaks, tune JVM heap size, fix chunk loading issues and optimise plugin memory usage.

What Causes OutOfMemoryError?

When your server prints java.lang.OutOfMemoryError: Java heap space, the JVM has exhausted all allocated RAM and cannot allocate new objects. The server will either crash immediately or enter an unstable state where GC runs constantly but cannot free enough memory. Understanding why your minecraft server out of memory error occurs is essential to fixing it properly.

Step 1: Check Your Heap Allocation

Open your start script and look at the -Xmx flag. This sets the maximum heap size. Common recommendations:

  • 1-5 players, vanilla-like: 4-6 GB
  • 10-20 players, plugins: 8-10 GB
  • 20-50 players, heavy plugins: 12-16 GB
  • Modded servers (Forge/Fabric): 8-16 GB depending on mod count

Always set -Xms equal to -Xmx. This prevents the JVM from wasting CPU on heap resizing and avoids fragmentation.

Step 2: Identify Memory Leaks

If your server runs fine for hours then suddenly crashes with an OOM error, you likely have a memory leak, something is allocating objects that are never freed.

  1. Install Spark and run /spark heapdump. This generates a .hprof file.
  2. Open the heap dump in Eclipse MAT or VisualVM.
  3. Look at the "Dominator Tree", the largest objects by retained size reveal what is consuming memory.
  4. Common leaks: plugins that cache player data without clearing it on disconnect, chunk data held in memory by world editors, and logging frameworks that buffer too aggressively.

Step 3: Reduce Loaded Chunks

Each loaded chunk consumes roughly 10-20 KB of heap. A view distance of 10 with 50 players means tens of thousands of loaded chunks. Reduce view-distance and simulation-distance in server.properties. A view-distance of 8 and simulation-distance of 6 is a solid balance.

Also check for plugins that force-load chunks (e.g. chunk loaders, teleportation plugins that pre-load destinations). These can hold thousands of chunks in memory indefinitely, causing your minecraft server out of memory condition.

Step 4: Tune Garbage Collection

Use G1GC with Aikar's flags (see Can't Keep Up fix guide). Key settings:

-XX:+UseG1GC -XX:G1HeapRegionSize=8M
-XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=200
-XX:InitiatingHeapOccupancyPercent=15

Avoid -XX:+UseConcMarkSweepGC, CMS is deprecated in modern Java. G1GC handles large heaps much better.

Step 5: Audit Plugins for Memory Usage

Some plugins are known memory hogs:

  • Dynmap: Can consume 2+ GB for large worlds. Use the lowres render and limit the map radius.
  • CoreProtect: The in-memory cache can grow large. Reduce max-pool-size in its config.
  • Citizens/NPC plugins: Each NPC with complex pathfinding holds AI data in memory.

Emergency Measures

If your server is crashing right now:

  1. Increase -Xmx temporarily (if you have available system RAM).
  2. Add -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./heapdump.hprof to your start flags so the next crash produces a dump for analysis.
  3. Restart the server, OOM conditions corrupt internal state, so a clean restart is always recommended.

If the minecraft server out of memory error persists after increasing RAM, the problem is a leak, not insufficient allocation. Focus on Step 2 and Step 5 above. See also fixing high CPU usage since GC thrashing from memory pressure shows up as CPU spikes too.

Want to just play without the headaches? Join Astroworld MC, IP play.astroworldmc.com, Java + Bedrock.

Related Tools & Resources

🔧

Minecraft Tools

Calculators, generators & server tools

🧱

Item Database

Browse all Minecraft items, stats & recipes

⚒️

Crafting Recipes

Visual crafting guides for every recipe