minecraftseverity: can-fix
OOM

Minecraft java.lang.OutOfMemoryError — not enough RAM allocated

OutOfMemoryError — RAM allocation crash

95% fixable~3 mindifficulty: beginner

Verified against Minecraft Wiki — Tutorials/Setting up a Minecraft server/JVM optimization, Mojang Support — Minecraft Java Edition performance, Aikar's JVM Flags Guide — widely adopted server optimization reference · Updated June 2026

> quick_fix

Open your Minecraft launcher, go to the crashing installation's settings, click 'More Options,' and change the JVM argument -Xmx2G to -Xmx4G (or -Xmx6G for heavy modpacks). This doubles the RAM Minecraft is allowed to use and fixes the crash immediately.

JVM Arguments (paste into launcher profile → More Options → JVM Arguments):

Vanilla:  -Xmx2G -Xms1G
Modded:   -Xmx4G -Xms2G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200
Heavy:    -Xmx6G -Xms4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200

What causes this error

Java applications run inside the JVM with a fixed maximum heap size set by the -Xmx flag. Minecraft's default allocation is often 2GB, which is enough for vanilla but not for modded gameplay, high render distances, or resource-heavy shader packs. When the game tries to allocate an object and the heap is full, the garbage collector runs. If it can't free enough memory, the JVM throws java.lang.OutOfMemoryError and Minecraft crashes. The error appears most often when loading large worlds, entering new chunks with many entities, or during mod initialization.

> advertisementAdSense placeholder

How to fix it

  1. 01

    step 1

    Check current RAM allocation

    Press F3 in-game to open the debug screen. The top-right shows memory usage like 'Mem: 45% 921/2048MB.' If the total (2048MB here) is under 2GB for vanilla or under 4GB for modded, you need more.

    F3 debug screen memory line:
    Mem: 85% 1740/2048MB  ← Dangerously full, needs more allocation
    Mem: 30% 614/2048MB   ← Healthy, OOM cause is elsewhere
  2. 02

    step 2

    Increase RAM in launcher settings

    In the Minecraft Launcher: Installations → Edit → More Options → JVM Arguments. Find -Xmx2G and change it to -Xmx4G. In third-party launchers like Prism or MultiMC, look for Java/Memory settings and set Maximum Memory.

    Official Launcher: Installations → your profile → More Options → JVM Arguments
    Prism Launcher: Settings → Java → Maximum memory allocation
    CurseForge: Settings → Minecraft → Java Settings → Allocated Memory
    ATLauncher: Settings → Java/Minecraft → Maximum Memory
  3. 03

    step 3

    Verify your system has enough physical RAM

    You can't allocate more RAM to Minecraft than your system has free. If your PC has 8GB total, Windows uses 3-4GB, leaving 4-5GB available. Allocating 6GB to Minecraft will cause system-wide slowdowns or fail entirely.

    # Check total system RAM:
    # Windows (PowerShell):
    (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB
    
    # macOS:
    sysctl -n hw.memsize | awk '{print $1/1073741824 " GB"}'
    
    # Linux:
    free -h | grep Mem
  4. 04

    step 4

    Optimize JVM garbage collection flags

    The default garbage collector struggles with Minecraft's allocation pattern of many short-lived objects (chunk data, entity ticks). Use G1GC with tuned pause targets to reduce stutter and delay OOM crashes.

    Recommended JVM flags for modded Minecraft:
    -Xmx4G -Xms2G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:SurvivorRatio=32
  5. 05

    step 5

    Reduce in-game memory usage

    If you can't allocate more RAM, lower render distance to 8-10 chunks, turn off smooth lighting, reduce entity render distance, and remove unused resource packs. Each loaded chunk consumes ~1MB of heap.

How to verify the fix

  • Press F3 in-game and confirm memory usage stays below 80% of the allocated maximum
  • Play for 30+ minutes including chunk loading and the game does not crash
  • No new OutOfMemoryError entries appear in .minecraft/logs/latest.log

Why OOM happens at the runtime level

The JVM's heap is a fixed-size memory region set at launch by -Xmx. Minecraft allocates objects on this heap for chunk data (~1MB per loaded chunk), entity state, texture atlases, and mod data structures. When the GC cannot free enough space to satisfy a new allocation request, it throws java.lang.OutOfMemoryError: Java heap space. The JVM does not dynamically grow the heap beyond -Xmx. A separate variant, OutOfMemoryError: Metaspace, occurs when too many classes are loaded (common with 200+ mods) and can't be fixed by increasing -Xmx alone — it requires adding -XX:MaxMetaspaceSize=512m.

Common debug mistakes for OOM

  • Setting -Xmx but not -Xms, causing the JVM to start with minimal heap and spend the first 60 seconds constantly resizing and GC-ing during world load.
  • Using 32-bit Java which silently ignores -Xmx values above 1.5GB and crashes anyway.
  • Allocating 12-16GB 'just to be safe' which causes long GC pauses, worse performance, and sometimes triggers OOM sooner due to fragmentation.
  • Changing JVM arguments in the wrong launcher profile — the official launcher has per-installation JVM settings, not global ones.
  • Confusing system RAM with VRAM — OutOfMemoryError is about CPU-side heap, not GPU memory. Shaders cause OOM because they increase CPU-side texture processing, not because of VRAM.

When OOM signals a deeper problem

Chronic OutOfMemoryError with adequate RAM allocated (4GB+) usually points to a memory leak in a mod. Mods that cache chunk data, keep entity references after unload, or accumulate event listeners without cleanup cause the heap to fill over time, not at startup. The symptom is: game launches fine, plays for 20-60 minutes, then crashes. Profiling with VisualVM or the JVM's -XX:+HeapDumpOnOutOfMemoryError flag reveals which objects are consuming memory. If a single mod's objects dominate the heap dump, that mod has a leak and needs to be updated or replaced. Server operators should monitor with /gc command and watch for heap usage that only trends upward.

Editor's take

OutOfMemoryError is Minecraft's version of running out of desk space. The game asked Java for a chunk of memory, Java looked at the heap, found it completely full, ran garbage collection, still couldn't free enough, and gave up. The fix is almost always the same: give it a bigger desk.

The -Xmx flag is the single most important JVM argument for Minecraft players to understand. It sets the maximum heap size in gigabytes. Minecraft's default is often 2GB, which was fine in 2015 when worlds were simpler and nobody ran 200 mods. Modern modpacks routinely need 4-6GB. The official launcher lets you change this under Installations → More Options → JVM Arguments, but it's buried deep enough that most players never find it.

The counter-intuitive part: allocating too much RAM is also a problem. Players with 32GB of system RAM set -Xmx16G thinking more is always better. It isn't. Java's garbage collector has to scan the entire heap to find dead objects, and with 16GB to search through, GC pauses can hit 500ms — visible as hard stutters every few seconds. The sweet spot for most modded setups is 4-6GB. Only massive modpacks (300+ mods with terrain generation overhauls) genuinely need 8GB.

The GC flags matter more than most guides admit. Minecraft's allocation pattern is unusual for a Java application: it creates and discards millions of short-lived objects per second (chunk mesh data, entity position updates, light recalculations). The default GC isn't tuned for this. Switching to G1GC with Aikar's flags — a set of JVM arguments originally developed for Paper/Spigot servers — reduces stutter and delays OOM by 30-40% in real-world modded gameplay. These flags are effectively the community standard and have been battle-tested across millions of server hours.

By Bikram Nath · Curator · Updated June 2026

Frequently asked questions

Can I allocate all my system RAM to Minecraft?

No. Your operating system needs 2-4GB to function, and other programs need memory too. As a rule, never allocate more than half your total RAM to Minecraft. On an 8GB system, 4GB max. On 16GB, 6-8GB max.

Why does allocating too much RAM (like 16GB) make performance worse?

The garbage collector has to scan a much larger heap to find dead objects. With 16GB allocated, GC pauses can last hundreds of milliseconds, causing visible stutters. Minecraft rarely needs more than 8GB even with 300+ mods. Allocate only what you need.

I increased RAM but still get OutOfMemoryError — why?

You may be running 32-bit Java, which caps at ~1.5GB regardless of -Xmx. Run 'java -version' and check for '64-Bit.' If it says '32-Bit,' install 64-bit Java. Also check that your launcher is actually using the Java installation you configured.

disclosure:Errordex runs AdSense, has zero third-party affiliate or sponsored links, and occasionally links to the editor’s own paid digital products (clearly labelled). Every fix is cross-referenced against the official sources listed in the “sources” sidebar before it ships. If a fix here didn’t work for you, please email so we can update the page.