NIO's Secret Cache: Unbounded Native Memory Use

The JDK internally caches a single, maximum-sized temporary direct `ByteBuffer` per thread for NIO I/O operations, even when application code uses heap buffers. This unbounded cache can unexpectedly consume gigabytes of off-heap memory, a behavior mitigated by the `-Djdk.nio.maxCachedBufferSize` flag in JDK 9 and later.

Sources

Open the full topic