jconsole could not relfect usage of non-heap memory

234 views Asked by At

I use ByteBuffer.allocateDirect(int) to allocate direct buffer(100M) on non-heap space until java.lang.OutOfMemoryError: Direct buffer memory error thrown.

But when I use jconsole to monitoring the non-heap memory usage, no direct buffer used memory is shown.

import java.nio.ByteBuffer;
import java.util.LinkedList;

public class BufferTest {
    public static void main(String[] args) throws InterruptedException {
        LinkedList<ByteBuffer> ll = new LinkedList<ByteBuffer>();
        int i = 0;

        while (true) {
            ByteBuffer buffer = ByteBuffer.allocateDirect(100 * 1024 * 1024);
            while (buffer.hasRemaining()) {
                buffer.put((byte) 1);
            }
            ll.add(buffer);

            System.out.println(i++ + "\t" + buffer.isDirect() + "\t" + buffer.limit());
            Thread.sleep(1000);
        }
    }
}

enter image description here

0

There are 0 answers