advancedJVM Internals & Memory

What is a DirectByteBuffer, and why can it cause OutOfMemoryError even when heap usage looks fine?

ByteBuffer.allocateDirect() allocates off-heap, native OS memory — invisible to normal heap monitoring tools. Exhausting it throws 'Direct buffer memory' OOM even with plenty of heap free; tune with -XX:MaxDirectMemorySize and check with jcmd VM.native_memory.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Your Java process consumes 100% CPU — walk through diagnosing exactly which thread and method is responsible.← Back to all Core Java questions