I have a java process which creates a short lived thread and a short live direct byte buffer in them continuously every 10 milliseconds which is eating up system memory. Though the byte buffers are short-lived, they are not getting cleaned up.
I root caused the issue and added maxDirectMemorySize and also maxCacheBufferSize
too, although it still exhibits the same behavior.
Is it because of maxCacheBufferSize
? I mean every thread is allocating a direct memory equivalent to maxCacheBufferSize
?
-XX:MaxDirectMemorySize=256M
-Djdk.nio.maxCachedBufferSize=262144
while(true) {
for (int i=0; i<100; i++) {
es.execute(() -> {
try {
ByteBuffer buffer = ByteBuffer.allocateDirect(2048);
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
});
}