How to Fix OutOfMemoryError: Direct Buffer Memory
Direct buffer memory lives outside the Java heap and its limit defaults to your -Xmx, so a low -XX:MaxDirectMemorySize flag often causes this error instead of fixing it.
Quick Fix
Look for -XX:MaxDirectMemorySize in your start command. If it is lower than -Xmx, remove it: without the flag Java allows as much direct memory as the maximum heap size.
Error Message
java.lang.OutOfMemoryError: Direct buffer memoryHow to Fix
Remove a -XX:MaxDirectMemorySize value that is lower than your -Xmx, or raise it. If you never added the flag, don't add one with a small number.
Raise -Xmx if the server is short on memory in general; the default direct memory limit grows with it.
Leave room on the machine. Direct buffers sit outside the heap, so the Java process uses more RAM than -Xmx alone, and on a host or container with a hard memory cap -Xmx should stay well below that cap.
Read the stack trace under the error. Frames from io.netty point at networking; a mod or plugin package name tells you what to update or remove.
Update the mods, plugins or proxy software named in the trace, and test without recently added mods if the error started after installing them.
Common Causes
- A -XX:MaxDirectMemorySize flag set lower than the maximum heap. Without the flag, Java uses the maximum heap size as the direct memory limit, so a fixed value like 512m can shrink it.
- Network load. Minecraft uses the Netty library for its connections, and Netty's buffers come out of this same direct memory.
- A mod or plugin that keeps allocating direct buffers and never releases them.
- A heap that is too small overall, since the default direct memory limit follows -Xmx.
Diagnostic Steps
- Copy the full error line, including any numbers in it.
- Check the start command or hosting panel for -Xmx and -XX:MaxDirectMemorySize.
- Remove or raise a direct memory limit that is lower than -Xmx.
- Restart and watch whether the error comes back under the same load.
- If it does, look at the stack trace for the mod or plugin that allocates the memory.
FAQ
What is direct buffer memory?
Memory that Java allocates outside the garbage-collected heap, mostly for I/O. Minecraft's networking library, Netty, uses it for connection buffers.
What is the default MaxDirectMemorySize?
If you don't set it, the JVM uses the maximum heap size as the limit, which is normally your -Xmx value. Setting the flag replaces that default with the number you give it.
Why does the message look different on my server?
Newer Java versions write "Cannot reserve N bytes of direct buffer memory (allocated: X, limit: Y)", while Java 8 writes "Direct buffer memory". Netty throws its own OutOfDirectMemoryError: "failed to allocate N byte(s) of direct memory (used: X, max: Y)". All of them mean direct memory ran out, and the numbers show where the limit was.
Related Errors
How to Fix java.lang.OutOfMemoryError
java.lang.OutOfMemoryError: Java heap space
How to Fix Java Heap Space on Servers
java.lang.OutOfMemoryError: Java heap space (Server)
How to Fix Minecraft Ran Out of Memory
Minecraft has run out of memory
How to Fix Networking Buffer Overflow Crash
io.netty.handler.codec.EncoderException: Buffer overflow / Packet size exceeded