ACLClouds
ACLClouds

Minecraft shows OutOfMemoryError or closes due to lack of RAM

A memory error can come from too many chunks, a modpack that is too heavy, or a plugin that holds on to objects in memory.

A memory error can come from too many chunks, a modpack that is too heavy, or a plugin that holds on to objects in memory. Increasing the RAM without measuring does not always fix the cause.

Step-by-step procedure

  1. Read the end of the log

    Look for OutOfMemoryError, Java heap space, Cannot reserve bytes of direct buffer memory, GC overhead or a code 137 stop.

  2. Reduce the view distance

    Decrease view-distance and simulation-distance in server.properties, then restart only once.

  3. Isolate plugins and mods

    Update your plugins and mods, then temporarily disable the most recently added one if the memory increase started after it was installed.

  4. Adjust the resources

    If normal usage regularly reaches the limit, choose a plan with more RAM while keeping 15 to 20% headroom.

Cautious setting

view-distance=8
simulation-distance=6

Cap direct memory (Netty) in the startup command

-Xmx3G -XX:MaxDirectMemorySize=512M

Diagnose memory with spark

spark health
spark heapsummary

Understanding the memory limit

The server runs in a container whose RAM is capped by your plan. Inside it, Java reserves the heap, where chunks, entities and plugin data live; the rest is used by Java itself and its threads.

This leads to two different symptoms. Java heap space means the heap is full. A stop with code 137 and no Java message means the whole container went over its limit and the system killed the process.

The "Startup command", under "Startup", shows how the heap size is set: -Xmx or -XX:MaxRAMPercentage. If you edit it, never give -Xmx all of the plan’s RAM: keep a margin of about 10 to 15% for Java itself.

Direct memory: “Cannot reserve bytes of direct buffer memory”

The message java.lang.OutOfMemoryError: Cannot reserve 16384 bytes of direct buffer memory (allocated: …, limit: …) is not about the heap but about direct, off-heap memory that Netty uses for network packets. Its limit (-XX:MaxDirectMemorySize) defaults to the -Xmx value; when -Xmx takes almost all the plan’s RAM, nothing is left for these buffers and the error shows up at the first network spike: several players joining, chunk loading at a high view distance, a plugin sending many packets.

Two settings are usually enough: lower -Xmx to leave 10 to 15% of the plan’s RAM outside the heap, and set -XX:MaxDirectMemorySize to an explicit value (256M to 1G depending on the player count). If the error persists, reduce view-distance, update Java and the server, then find the plugin sending the most packets with spark profiler.

Measure before changing plan

The "Memory" line in the console measures the whole container. Java keeps reserved memory even after a cleanup, so a high but stable value is normal. Note instead when the error happens: when several players join, during exploration, or after a shorter and shorter uptime.

  • spark health shows heap usage and garbage collector pause times. spark is built into recent Paper versions, or can be installed as a plugin.
  • spark heapsummary lists the objects using the most memory and helps identify the plugin or mod at fault.

Frequently asked questions

What does Cannot reserve bytes of direct buffer memory mean?

Java’s direct memory, used by Netty for networking, is full; it is separate from the heap. Set -XX:MaxDirectMemorySize (for example 512M) in the startup command and keep -Xmx 10 to 15% below the plan’s RAM. Then reduce view-distance if many players explore at the same time.

What does a stop with code 137 mean?

The system killed the process because the container reached its RAM limit; Java had no time to log an error. Reduce the load, check under "Startup" that -Xmx is not too close to the plan’s RAM, then change plan if normal usage stays at the maximum.

What does GC overhead limit exceeded mean?

Java spends almost all its time freeing memory without reclaiming enough. The cause is the same as for Java heap space: too much data loaded, or a leak.

Why does the unable to create native thread error appear?

It concerns threads, not the heap: the server reached the container’s process or memory limit, and the panel opens the "Possible resource limit reached" window. A plugin that keeps creating threads is often the cause: remove the last one added, then contact support with the displayed error if it persists.

Is adding RAM enough to fix the problem?

Only if normal usage really exceeds the limit, for example with a heavy modpack. With a leak, more RAM only delays the crash by a few hours. Measure, fix the cause, then use "Change plan" if the margin is still too small.