Minecraft out of memory error, java.lang.OutOfMemoryError

The error java.lang.OutOfMemoryError means Minecraft ran out of the memory Java was allowed to use. It is not the same as the PC running out of RAM: the game is given a fixed allocation when it starts, and when that allocation fills up, the game crashes even if the PC has free memory left. The fix is to raise the allocation, reduce what the game loads, or both.

The fix, in order

  1. Raise the RAM allocation in the launcher. Open Installations, edit the profile, open More Options, and find the JVM Arguments. Change the -Xmx value, for example from -Xmx2G to -Xmx4G, and save.
  2. Do not allocate more than the PC can spare. Leave at least 4G of RAM for Windows and other programs, so on a PC with 8G of total RAM, do not go above -Xmx4G.
  3. Close other programs before launching, especially browsers with many tabs, since they take memory the game could use.
  4. Lower the in-game load. Reduce the render distance, turn off fancy graphics, and remove heavy resource packs.
  5. Remove or replace heavy mods. Mods that add many blocks, entities, or dimensions use the most memory, so test with fewer mods and add them back gradually.
  6. Use the launcher's bundled Java. The official launcher includes a 64-bit Java runtime, which can use more memory than a 32-bit Java. Reinstalling the launcher refreshes it.
  7. Check for a memory leak in a mod. If the game runs fine for a while and then crashes as memory climbs, a mod is likely leaking memory, so test the unmodded game for comparison.
Do not set -Xmx higher than the free memory on the PC. An allocation the system cannot back makes the game slower, not faster, and can crash Windows itself.

If it still happens

If the error appears even with a large allocation, the cause is usually a mod or a world that needs more memory than the PC can give. Test the unmodded game, and if that works, the mod set is too heavy for the allocation, so either trim the mods or play with a smaller render distance.

Common questions

How much RAM should I give Minecraft? For an unmodded game, 2G to 4G is enough. For a modded game, 4G to 6G is a good range. More is not always better, since an oversized allocation leaves too little for Windows.

Does this error mean I need more RAM in my PC? Not necessarily. It usually means the game's allocation is too small, not that the PC lacks RAM. Raise the allocation first, and only consider a hardware upgrade if the PC itself is short on memory.

Related errors

Minecraft exit code -1 · Minecraft exit code 1 · Minecraft exit code 255 · Minecraft exit code -1073740791

Was this helpful?