Tree Host

How to Fix Out of Memory Errors on a Minecraft Server

Updated · by the Tree Host team

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:

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

CauseHow it shows upFix
Heap too small for the players and pluginsMemory sits near the limit all day, crashes at busy timesAdd memory or cut load
High view distanceMemory jumps when players explore or log in togetherLower view-distance and simulation-distance
Too many entitiesHuge mob farms, item piles, villager hallsCap mobs, clear drops, thin farms
Plugin or mod memory leakMemory climbs steadily and never drops, even when quietFind it with Spark, update or remove it
World generation by many players at onceSpikes while exploring new landPre-generate the world
Heavy modpack on a small planCrash during startup or first joinUse 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:

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:

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:

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:

-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 typeUsual memory
Vanilla or Paper, 1 to 5 players2 GB
Paper with plugins, 5 to 20 players4 GB
Light modpack4 GB or more
Large modpack or 20 to 60 players8 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

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.

More guides

← More guides