FreeMCHost logoFreeMCHost
All articles
Performance

Fix java.lang.OutOfMemoryError on a Minecraft Server

Heap space errors and servers killed without a message: how to find what eats the memory and what to change.

December 5, 20264 min read

Two different symptoms

  • java.lang.OutOfMemoryError: Java heap space: the memory given to Java is full.
  • The server disappears with Killed and no Java error: the whole process used more memory than the machine or container allows.

If the heap is full

  • Install spark and run /spark heapsummary to see what takes space.
  • Remove plugins or mods you do not use, one at a time.
  • Lower view-distance and simulation-distance.
  • Count entities: large mob farms and item piles are common causes.

If the process is killed

Do not set -Xmx equal to the total memory. Java needs room outside the heap. Keep roughly 10 to 25 percent free.

Estimate what you need

The RAM calculator gives a starting point and the startup flags generator builds a sensible command. If the server leaks memory, more RAM only delays the crash.