Minecraft Server Out of Memory: Fix "Java heap space" and Watchdog Crashes

Your Minecraft server crashed with java.lang.OutOfMemoryError: Java heap space, could not reserve enough space, or a watchdog tick error? How to read the message, how much RAM to give it, and what to change so it stops happening.

Updated
10 minutes
Intermediate
Contains affiliate links

Read the error first: three different problems

"Out of memory" covers three crashes with three different fixes. Find the line in the console or in the newest file under crash-reports/, then jump to the matching section.

Line in the logWhenMeaning
java.lang.OutOfMemoryError: Java heap spaceWhile runningThe heap you gave Java (-Xmx) is full. Section below.
Could not reserve enough space for object heapAt startupJava could not get the -Xmx you asked for. Section below.
A single server tick took 60.00 secondsWhile runningNot memory. The watchdog killed a stalled server. Section below.

Two more you may see: GC overhead limit exceeded is heap space by another name, the server spent almost all its time collecting garbage and freeing nothing. Unable to create native thread means the operating system, not the heap, ran out; lower -Xmx a little so the OS has room.

Java heap space: the server needs more than -Xmx

Every start script has a maximum heap, set with -Xmx. The world's loaded chunks, every entity, every plugin's data, and every player's inventory live inside it. When the next allocation does not fit and a full garbage collection cannot free enough, Java throws OutOfMemoryError: Java heap space and the server dies with it.

Two questions decide the fix.

Was the heap simply too small?

Look at the start script. A 26.x server on -Xmx1G or -Xmx1024M, which older tutorials still show, does not have enough to load a world with a few players. Raise it to at least 2 GB, and set -Xms to the same value:

java -Xms4G -Xmx4G -jar server.jar nogui

Use the RAM calculator for a figure based on your player count, plugins, and view distance, and read how much RAM to give it below for the limits.

Or did something fill a heap that used to be enough?

If the server ran for weeks on the same heap and now crashes, the load changed. The usual suspects, in order:

  • An entity build-up: a mob farm that stopped killing, a breeder that never culls, thousands of dropped items. Run /paper entity list on Paper, or teleport around with F3 watching the entity count.
  • Players spreading out. Each player loads their own set of chunks; ten explorers load far more than ten people in one base.
  • A new plugin that caches heavily, such as a map renderer (Dynmap, BlueMap) or a large logging plugin with a growing database.
  • A raised view-distance or simulation-distance. Memory grows with the square of the distance.

Raise the heap to stop the crashes today, then reduce the load so it does not just happen again at the new limit.

Could not reserve enough space for object heap

This one appears before the server even starts. Java asked the operating system for the heap you set and was refused. Three causes:

  • -Xmx is bigger than free RAM. A machine with 8 GB cannot give Java 8 GB; the OS needs 2 GB or so and other programs need theirs. Lower -Xmx.
  • 32-bit Java. It cannot address more than about 1.5 GB no matter how much RAM the machine has. Run java -version; if it says 32-Bit or lacks 64-Bit, install the 64-bit build. The Java 25 guide installs the right one.
  • A typo in the flag. -Xmx4GB is invalid; it is -Xmx4G or -Xmx4096M. A missing unit is read as bytes.

Watchdog: "A single server tick took 60.00 seconds"

People search for this as an out of memory error because it often follows one, but it is a different mechanism. The server watchdog kills the server when one game tick takes longer than max-tick-time in server.properties, which defaults to 60000 milliseconds. A tick should take 50. The crash report begins:

The server has stopped responding! This is (probably) not a Paper bug.
A single server tick took 60.00 seconds (should be max 0.05)
Considering it to be crashed, server will forcibly shutdown.

What stalled the tick is in the stack trace below that line. Common ones: a huge redstone machine, a chunk generation burst when a player flies with elytra, a plugin doing database work on the main thread, or the garbage collector pausing for seconds because the heap is nearly full. That last case is where memory comes in: a heap that is 95 percent used makes every collection slow, and the watchdog fires before the OutOfMemoryError does.

Raising max-tick-time hides the problem

Setting it to -1 disables the watchdog. The server then hangs silently instead of restarting. Find the cause in the stack trace instead.

How much RAM to give it

Three rules cover nearly every setup.

  1. Floor: 2 GB for any 26.x server. About 4 GB for ten players on Paper with a few plugins. 6 to 8 GB for a modpack.
  2. Ceiling: physical RAM minus 2 GB on a dedicated machine, and minus whatever else runs on it otherwise. Java also uses memory outside the heap, roughly another 10 to 20 percent, so -Xmx6G really costs about 7 GB.
  3. Xms equals Xmx on a dedicated server. It avoids heap resizing and makes garbage collection predictable.

More is not automatically better. Past the point of need, a larger heap means the collector has more to scan and pauses get longer. If the server lags with plenty of free heap, the bottleneck is the CPU or a slow tick, not memory.

Reduce the load

These changes cut memory use without buying anything, roughly in order of effect.

  • Lower view-distance and simulation-distance. 10 is the default. 8 halves the loaded area with little visible difference; 6 is fine for a small survival server.
  • Switch to PaperMC. It uses less memory per chunk and entity than vanilla and adds limits for mob and item build-up. The PaperMC guide covers the switch.
  • Cull entities. Kill dropped items with kill @e[type=item], fix farms that hoard mobs, and lower max-entity-cramming via the game rule.
  • Pre-generate the world. Chunk generation is the single most memory- and CPU-hungry thing the server does. The Chunky plugin generates the area inside your world border once, ahead of time.
  • Set a world border. worldborder set 10000 stops explorers loading endless new terrain.
  • Audit plugins. On Paper, /spark healthreport and /spark heapsummary (Paper bundles spark) show which plugin holds the memory.

Start script and flags

A plain start line is enough for most servers:

start.shbash
java -Xms4G -Xmx4G -jar server.jar nogui

For a server that stays up for days with many players, the garbage collector settings known as Aikar's flags reduce pauses. They are long, so copy them from the PaperMC documentation rather than retyping. They work with vanilla and Paper alike, on Java 25 as on 21. The one thing they do not do is reduce how much memory the server needs; size the heap first.

Check the fix worked

On Paper, /tps and /mspt show tick health, and /spark healthreport shows heap use over time. On vanilla, the F3 debug screen on an operator's client shows the server's memory in the top right. Steady use well under the maximum is the goal; a sawtooth that climbs to the ceiling and crashes means the load is still too high.

Frequently asked questions

What does java.lang.OutOfMemoryError: Java heap space mean?

Java hit the maximum heap you set with -Xmx, ran a full garbage collection, and still had no free memory for the next object. The server needs more heap than it was given, or something is holding memory it should have freed.

How much RAM should a Minecraft server have?

At least 2 GB for Minecraft 26.x, and about 4 GB for ten players on Paper with a handful of plugins. Modpacks need 6 to 8 GB or more. Leave at least 2 GB of physical RAM for the operating system. Our RAM calculator gives a figure for your setup.

Should -Xms equal -Xmx?

Yes for a dedicated server. It lets Java reserve the whole heap at start and avoids resizing pauses. On a shared desktop, a lower -Xms leaves memory for other programs until the server needs it.

Why does the server crash on startup with Could not reserve enough space for object heap?

The -Xmx value is larger than what Java can actually get: more than the machine's free RAM, or you are running a 32-bit Java that cannot address more than about 1.5 GB. Lower -Xmx or install 64-bit Java 25.

Does more RAM make the server faster?

Only up to the point where it stops running out. Beyond that, a bigger heap can make garbage collection pauses longer. Lag with plenty of free memory is a CPU or tick-time problem, not a RAM problem.

Will PaperMC fix out of memory errors?

It helps. Paper uses less memory per chunk and player than vanilla and lets you tune entity and chunk limits that vanilla cannot. It does not change the physical RAM you have, so size the heap correctly first.