How to fix OutOfMemoryError in Minecraft

Java ran out of the memory it was allowed to use, and the fix is usually one number in your launcher or your start command.

Updated 2026-09-26

What the error means

Java gives Minecraft a fixed pool of memory, the heap, and when the game asks for more than the pool holds it stops with this:

java.lang.OutOfMemoryError: Java heap space

The pool is smaller than your computer's RAM on purpose. The Minecraft Launcher starts the game with -Xmx2G, so 2 GB, which is plenty for vanilla and not enough for a big modpack or a busy server.

Two cousins. GC overhead limit exceeded is the same problem: Java spent nearly all its time cleaning up and got almost nothing back. unable to create native thread is different. It's a system limit, not the heap, and more memory usually makes it worse.

Give the game more memory

Most launchers have a memory setting per instance:

  • Minecraft Launcher: Installations, the three dots on your version, Edit, More options. In JVM arguments, change -Xmx2G to something bigger, like -Xmx4G.
  • Prism Launcher: instance settings, Java, then raise Maximum memory allocation.
  • Anything else: look for Memory, RAM or Java in the instance or launcher settings.

G is gigabytes, so -Xmx4G caps the game at 4 GB. Pick a number the machine can spare. On a 16 GB computer, 6 to 8 GB for the game is a sensible ceiling; leave the rest for the system, or everything slows down.

Give a server more memory

On a server it's the start command. Change the -Xmx number, and set -Xms to match:

java -Xms4G -Xmx4G -jar server.jar nogui

On a hosting panel there's usually a RAM slider instead, and your plan sets how far it goes.

When more memory doesn't help

Bigger isn't automatically better. Java has to sweep the heap now and then, and a very large one makes those pauses longer, which shows up as lag. If you raised the number and the error came back, it's probably something else:

  • A mod or plugin that eats more memory the longer the game runs, a leak. A crash that always arrives after an hour or two is the tell.
  • A high render distance, heavy shaders or a 512x resource pack on the client.
  • Too many loaded chunks or entities on a server.

The crash report and latest.log show what was running when memory ran out. How to read a Minecraft crash report shows where to look.

If Java says there isn't enough memory to start

There is insufficient memory for the Java Runtime Environment to continue, usually inside a file named hs_err_pid plus a number, means the computer itself is out of memory. It's the opposite problem: you asked Java for more than the machine has free. Lower the number or close other programs.

Send the log

Asking for help? Send latest.log and the newest crash report. Drop the file onto minelog for a link; IP addresses and the like are hidden first.

Questions

How much RAM does Minecraft need?

Vanilla is fine on a few gigabytes. Modpacks and busy servers want more, often 4 to 8 GB, and the modpack's page usually says how much. Never hand Java more than the computer can spare.

What does -Xmx mean?

The largest amount of memory Java may use: -Xmx4G is 4 gigabytes at most. -Xms is how much it grabs at startup.

Why does Minecraft still run out of memory after I gave it more?

Probably something is holding on to memory, like a mod or plugin with a leak. If it always dies after about the same playing time, that's your answer.

Keep reading

Share a log