How to Fix Out of Memory Errors on a Minecraft Server
An out of memory error means the server's Java heap is full. The fix, in order: lower the view distance, remove heavy plugins or mods, clear huge entity counts, and check for a leak with Spark. If the server is simply too small for its players and mods, give it more memory. Setting -Xmx higher alone only hides a leak.
What the error actually looks like
You will see one of these in the console or in logs/latest.log, often right before the server stops or freezes:
java.lang.OutOfMemoryError: Java heap space: the heap is full. This is the common one.java.lang.OutOfMemoryError: GC overhead limit exceeded: Java spends almost all its time collecting garbage and frees almost nothing. Same cause, caught earlier.java.lang.OutOfMemoryError: Metaspace: too many classes are loaded. Rare, and usually a plugin reloading itself over and over.Killedor exit code 137 with no Java error: the system stopped the process because it used more than its total limit, which includes memory outside the heap.
The heap is the part of memory where the world, chunks, entities and plugin data live. It has a ceiling set by the -Xmx flag. When the game needs more than that ceiling, Java throws the error. It says nothing about how much free RAM your computer has, which is why adding RAM to the machine alone does not help.
Why servers run out of memory
| Cause | How it shows up | Fix |
|---|---|---|
| Heap too small for the players and plugins | Memory sits near the limit all day, crashes at busy times | Add memory or cut load |
| High view distance | Memory jumps when players explore or log in together | Lower view-distance and simulation-distance |
| Too many entities | Huge mob farms, item piles, villager halls | Cap mobs, clear drops, thin farms |
| Plugin or mod memory leak | Memory climbs steadily and never drops, even when quiet | Find it with Spark, update or remove it |
| World generation by many players at once | Spikes while exploring new land | Pre-generate the world |
| Heavy modpack on a small plan | Crash during startup or first join | Use a plan sized for the pack |
1. Check how much memory the server really uses
Do not guess. Look at the memory graph over a few hours, with players online. Two shapes tell you everything:
- A sawtooth that stays well below the limit: the server is healthy. Memory rises, garbage collection drops it, and it repeats.
- A line that sits near the limit, or climbs a little higher after each drop: the server is too small, or something is leaking.
Install Spark if you do not have it. It is a plugin for Paper and Purpur and a mod for Fabric. Run /spark health for a quick view of memory and TPS. Run /spark heapsummary to list which kinds of objects fill the heap. If you see a plugin's classes at the top of that list with a huge count, you found your leak.
2. Lower view distance and simulation distance
This is the cheapest fix and often enough on its own. Open server.properties and set:
view-distance=8(the default is 10)simulation-distance=6(the default is 10)
Restart the server after saving. Fewer loaded chunks means fewer entities, tile entities and block data in memory. Our guide on view distance vs simulation distance explains what each one does and what to set for different player counts.
3. Cut entities and pre-generate the world
Mobs, dropped items, minecarts and villagers all cost memory and tick time. A few thousand loose items in one chunk is a classic cause. Kill them with /kill @e[type=item] (check the count first with /execute if entity @e[type=item]) and fix the farm that made them. Lower the spawn-limits values in bukkit.yml to cap how many mobs spawn.
Generating new terrain is the heaviest thing a server does. If three players run in different directions on a fresh world, memory spikes. Pre-generate the world with Chunky once, while nobody is online, and that spike goes away for good.
4. Find and remove a leaking plugin or mod
A leak is memory that is never given back. The sign is a graph that climbs for hours even when the server is quiet. To find the cause:
- Update every plugin and mod. Many leaks are fixed in a newer version.
- Run
/spark heapsummaryand look at the top classes. Note which plugin they belong to. - Remove half of your plugins, restart, and watch the graph. Keep halving until the climb stops. This is slow but it always works.
- Check the plugin's issue tracker for the same symptom, and report it with your Spark link if nobody has.
If you are not sure how plugins get added in the first place, see how to add plugins to a Minecraft server.
5. Set the memory flags correctly (if you run the server yourself)
If you start the server from a script, the memory is set in the Java command. A correct line for a 6 GB server looks like this:
java -Xms6G -Xmx6G -jar server.jar nogui
-Xmx is the maximum heap and -Xms is the starting heap. For a dedicated server, set them to the same value. The machine needs more memory than the heap alone, because Java also uses memory for itself and for native code, and the operating system needs some too. As a rough rule, leave 1 to 2 GB free on top of the heap. If you give the heap all the RAM in the machine, the system may kill the process instead, which looks like Killed with no Java error.
Two more checks. First, use 64-bit Java: a 32-bit Java cannot use more than about 4 GB and ignores a larger -Xmx. Run java -version and look for 64-Bit. Second, use the Java version your Minecraft version needs. Minecraft 1.20.5 and newer needs Java 21. Older versions from 1.18 to 1.20.4 need Java 17.
Tuning flags such as the well known Aikar flags change how the garbage collector behaves. They help with lag spikes from garbage collection on servers with 6 GB or more. They do not fix a heap that is simply too small, so set the size first and add flags only if Spark shows long garbage collection pauses.
To catch a rare crash for later study, add -XX:+HeapDumpOnOutOfMemoryError to the command. Java then writes a .hprof file when it runs out. These files are as large as the heap, so delete them when you are done.
6. Add memory when the server is just too small
After steps 2 to 4, if memory still sits near the limit at normal player counts, the server needs more. Our RAM guide has numbers for each kind of server. The short version:
| Server type | Usual memory |
|---|---|
| Vanilla or Paper, 1 to 5 players | 2 GB |
| Paper with plugins, 5 to 20 players | 4 GB |
| Light modpack | 4 GB or more |
| Large modpack or 20 to 60 players | 8 GB or more |
Some jobs make a server need more only for a short time, such as pre-generation or a big world edit. For those, do the job, then go back to what you had.
What to do on Tree Host
On Tree Host, memory, CPU and disk come from your plan and are not set in Settings. If a server uses more than its plan allows, it stops with "ran out of memory" in the console. The Troubleshooting guide lists the same fixes: remove heavy plugins or mods, lower view distance in Settings, or move to a bigger plan. The server header shows memory in use next to the plan limit, and the Performance tab charts memory over the last hour, 6 hours or 24 hours, so you can see which shape your graph has before you change anything.
Tree Host has not launched yet. Creating your own servers opens at launch, and anyone signed in can try the shared demo server now. Plan sizes and prices are on the pricing page.
A quick order of attack
- Read the exact error and match it to the list above.
- Watch the memory graph and Spark's
/spark healthfor a few hours with players online. - Lower
view-distanceto 8 andsimulation-distanceto 6. - Pre-generate the world and clear item and mob buildups.
- Update plugins and mods, then bisect to find any leak.
- Only then add memory, and match it to your player count and mod list.
If lag is your problem as much as crashes, read how to fix Minecraft server lag next. Memory pressure and lag usually come from the same causes.
Want a server with a memory graph and a crash doctor built in? Tree Host shows memory use next to your plan limit.