Logs / Error guide / Minecraft
Minecraft: “java.lang.OutOfMemoryError: Java heap space”
What the message means
Java has used up the memory it was allowed to reserve for the Minecraft server. The server can't create any new objects – it usually freezes briefly and then crashes, often while chunks are being saved or generated.
What it looks like in the log
[14:02:11] [Server thread/INFO]: Starting minecraft server version 1.21.1
[14:02:11] [Server thread/INFO]: Loading properties
[14:02:19] [Server thread/INFO]: Preparing level "world"
[14:02:31] [Server thread/INFO]: Done (19.412s)! For help, type "help"
[14:37:52] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 4120ms or 82 ticks behind
[14:38:40] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOf(Arrays.java:3537)
at net.minecraft.world.level.chunk.storage.RegionFile.write(RegionFile.java:220)
[14:38:41] [Server thread/INFO]: Stopping server
Excerpt from an example log, marked the way the analysis marks it.
Common causes
- The -Xmx value in the start command is too small for the world, player count and mods.
- A modpack or many plugins need more RAM than the server has. Large modpacks quickly reach 8 to 12 GB.
- High view distance (view-distance) or simulation distance: every player then keeps many chunks in memory.
- Fast exploring or pre-generation creates many new chunks at once.
- A mod or plugin with a memory leak: usage climbs hour by hour until the server crashes.
How to fix it
- Check the -Xmx value in the start command (for example -Xmx6G). It should be about 1 to 1.5 GB below your plan's RAM so Java itself still has room.
- Lower view-distance in server.properties to 8 to 10 and simulation-distance to 6 to 8. On Paper, you can also set the view distance for players separately.
- If usage climbs slowly until the crash, look for the leak: remove plugins or mods one at a time and watch whether RAM stays stable. On Paper, the command /spark heapsummary helps.
- Pre-generate large worlds with a plugin like Chunky – calmly, when nobody is playing.
- If the RAM isn't enough for your modpack at all, get a plan with more memory.
If the log says “Exit code 137” instead of the Java message, it wasn't Java but the system that stopped the server, because all of the container's memory was full. In that case, -Xmx is more likely set too high than too low.