How to Fix java.lang.OutOfMemoryError
Fix the java.lang.OutOfMemoryError in Minecraft by increasing RAM allocation, optimizing settings, and removing memory-heavy mods.
Quick Fix
Increase allocated RAM to at least 4GB in your launcher JVM arguments: -Xmx4G -Xms2G
Error Message
java.lang.OutOfMemoryError: Java heap spaceHow to Fix
Open your launcher, go to Installations, edit your profile, and set JVM arguments to -Xmx4G -Xms2G
Lower your render distance to 8-12 chunks
Remove unused mods and resource packs
Update Java to the latest version (Java 21 for 1.21+)
Close other memory-heavy programs while playing
If using a server, increase the -Xmx value in start.sh or start.bat
Common Causes
- Not enough RAM allocated to Minecraft
- Too many mods or resource packs loaded
- Memory leak from a mod or plugin
- Large render distance with limited RAM
Diagnostic Steps
- Check current RAM allocation in launcher settings
- Verify Java version with java -version in terminal
- Monitor memory usage with F3 debug screen in-game
- Remove mods one by one if the issue persists after increasing RAM
FAQ
How much RAM should I allocate to Minecraft?
4-6GB for modded, 2-4GB for vanilla. Never allocate more than 75% of your total system RAM.
Why does Minecraft keep running out of memory?
Usually caused by too many mods, high render distance, or a memory leak. Try reducing mods and render distance first.