Skip to content

Minecraft "java.lang.OutOfMemoryError: Java heap space": What It Means and How to Fix It

Java heap space OOM explained: what the JVM actually ran out of, the five variants and what each of them means, and why raising -Xmx is not the fix here.

Updated August 19, 2026
Minecraft

This is what an out-of-memory crash looks like in logs/latest.log. The first line is the server catching it; the second is the failure itself:

[Server thread/ERROR]: Encountered an unexpected exception
java.lang.OutOfMemoryError: Java heap space
Console output

Java heap space is the exact message the Java Virtual Machine produces when it cannot satisfy an allocation. It is not a Minecraft message, which is why every guide phrases the fix as "raise -Xmx". On a GameServerKings server there is no -Xmx to raise, and this page explains what to do instead.

For the wider question of how much memory a Minecraft server needs and how the heap is sized here, see Minecraft Server RAM and JVM Flags; this page is about the crash itself.

What It Actually Means

The Java heap is the region of memory the JVM hands out for objects. Minecraft allocates into it constantly — chunks, entities, block entities, packet buffers, everything.

OutOfMemoryError: Java heap space means the JVM tried to allocate an object, found no free space, ran a full garbage collection to make some, and still had no room. Two things follow from that:

  • The heap was already full before the crash. The collector had been working harder and harder for a while. An OOM crash after a long stretch of stuttering and complaints is the normal shape of this failure, not a coincidence.
  • The failing allocation is rarely the culprit. The stack trace points at whatever asked for memory last. That line is almost never the reason the heap was full, so do not chase it.

This is the heap, not your plan's RAM

Your plan's RAM is the ceiling for the whole container. The heap is a portion of that, and it is what filled up. The two failures look completely different: a full heap throws this error and writes a crash report; a container that exceeds its limit is killed from outside, with no error and no crash report at all — the log just stops mid-line. If you have no OutOfMemoryError in the log, you are looking at the second problem, not this one.

The Five Variants, and Which One You Have

OutOfMemoryError is one exception class with several messages, and they do not share a cause. All five below are produced by the Java 25 runtime your server runs on.

Message What ran out Same fix?
Java heap space The heap. The ordinary case Yes — this page
GC overhead limit exceeded Nothing yet, but the collector is spending nearly all its time achieving nearly nothing. A pre-emptive abort Yes
Metaspace Class metadata, which lives outside the heap. Usually a very large modpack, or a plugin loading classes in a loop No
unable to create native thread: possibly out of memory or process/resource limits reached Thread stacks, also outside the heap. Usually one add-on spawning threads without bound No
Requested array size exceeds VM limit Nothing. Something asked for an array larger than Java permits. Always a bug in a mod or plugin No

A sixth exists and is worth recognising because the wording changed recently: Cannot reserve N bytes of direct buffer memory (allocated: X, limit: Y). That is off-heap network buffer space, not the heap.

Only the first two are memory-sizing problems. The middle three are pressure on the roughly 5% of your container that sits outside the heap, and more heap makes them worse, not better.

Why "Raise Xmx" Does Not Apply Here

Our Minecraft servers launch with this command, and the command box on the Startup tab is read-only:

java -Xms128M -XX:+IgnoreUnrecognizedVMOptions -XX:MaxRAMPercentage=95.0 \
  -Dterminal.jline=false -Dterminal.ansi=true \
  -jar server.jar \
  $EXTRA_FLAGS
The launch command on a GSK Minecraft (Java) server

There is no -Xmx, and there is no MEMORY variable. -XX:MaxRAMPercentage=95.0 caps the heap at 95% of the memory available to the container, so the heap ceiling is derived from your plan's RAM automatically and moves with it. The editable variables are Framework, Minecraft Version, Build Number, Server Jar File, Extra Flags and Accept Mojang EULA — and that is the complete list.

Putting -Xmx in Extra Flags will not give you more memory

Extra Flags is appended after -jar server.jar. Everything after the jar name is handed to the Minecraft server as a program argument, not to the JVM — by that point the heap has already been sized. The -XX:+IgnoreUnrecognizedVMOptions in the command is not a safety net for this either: it governs the section before -jar, and never sees what you typed. Extra Flags is for server arguments such as --safeMode or --nogui.

So the two levers you genuinely have are: give the server less to hold, or move to a plan with more RAM. Everything below is the first of those.

Causes, in the Order to Check Them

1. View distance and simulation distance

The largest single lever, and it multiplies by player count. Both default to 10, which is a 21 × 21 square of loaded chunks per player. Dropping view-distance to 8 loads 289 chunks per player instead of 441 — a 34% cut that most players never notice.

Check: read view-distance and simulation-distance in server.properties. If either is above 10 on a busy server, start there.

view-distance=8
simulation-distance=6
server.properties

Lower simulation-distance first: it governs which chunks actually tick, and it is the more expensive of the two.

2. Accumulated entities

Item frames, armour stands, dropped items, mob farms, minecart chains and boats accumulate for months and are never collected. On an old world this is frequently the entire problem.

Check: run a profiler and look at the entity counts per world before assuming anything — Diagnosing Minecraft Server Lag covers /spark and the vanilla /tick command. A world that has been running a year with heavy farms can hold tens of thousands of entities.

3. A modpack larger than the plan

Mods consume heap at boot, before any player joins, in registries and recipe data. A 150-plus-mod pack can take 3–4 GB standing still. Pack authors publish a memory figure; theirs is measured and yours is not.

Check: find the pack's stated requirement and compare it to your plan's RAM. If the pack says 10 GB and your plan is 6 GB, you have your answer and no amount of tuning will change it. How to Install a Minecraft Modpack Server covers pack sizing.

4. One plugin caching without limit

A live map renderer, a logging plugin such as CoreProtect, or a permissions plugin with a very large user table can hold hundreds of megabytes each.

Check: the heap dump is the rigorous answer, but bisection is faster: disable half your plugins, restart, and see whether the crash still comes. Reading Minecraft Server Logs and Crash Reports sets out the bisection method in full.

5. Genuinely undersized

If the world is tidy, the distances are sane and the pack fits, then the plan is simply too small for what you are running. The heap ceiling is a percentage of your allocation, so a larger allocation is the only way to raise it.

When Memory Is Not the Real Problem

Three symptoms get blamed on memory and are not:

  • A memory meter sitting at 90%. That is how Java works. The heap grows and the collector does not hand it back to the operating system. PaperMC describes high memory usage as expected and explicitly not a memory leak. Only crashes and long collection pauses are problems.
  • Lag with no crash. The Minecraft tick loop runs on a single thread. If ticks are slow because four thousand entities need updating, more heap changes nothing at all. Diagnose before you buy — Minecraft "Can't keep up! Is the server overloaded?" explains why that particular warning is a symptom rather than a cause.
  • A process that vanished with no error. No OutOfMemoryError, no crash report, the log stops mid-line: that is a kill from outside the JVM, and the thing to mention in a ticket is the off-heap margin, not the heap.

What to Send Support

  1. logs/latest.log from the crashed run, as a file. The lines before the exception matter more than the exception.
  2. The crash report, if crash-reports/ gained one.
  3. Your view-distance, simulation-distance and max-players.
  4. Server type, Minecraft version and your plugin or mod list — a pack name and version is enough.
  5. Whether it crashes at a predictable time, such as during autosave or when a particular area loads.

Other Named Errors in This Cluster

One page per message, all six indexed from Reading Minecraft Server Logs and Crash Reports:


Made with 💜 by GameServerKings

Need a Minecraft server?

Deploy an instantly-provisioned Minecraft server on high-clock hardware — DDoS protected, no contracts, cancel anytime.

From $4.80 /month