There is a cleaner in DirectByteBuffer. When recycling, the clean() method of this cleaner is called. GC will use this cleaner to recycle, although it is not recycled into the Java heap
The implementation of allocation and recycling is to call Unsafe’s allocateMemory and freeMemory, which are actually the system calls malloc and free
If you need to take the initiative to clean up, you need to use a hack method. You can refer to java. When all streams are closed, will an error be reported when deleting files on the hard disk? My answer
If it is a system cleanup, when it finds that the off-heap memory is insufficient, it will display the call System.gc()来清理堆外内存,可以通过添加-XX:+DisableExplicitGC to overflow the off-heap memory
There is a cleaner in DirectByteBuffer. When recycling, the clean() method of this cleaner is called. GC will use this cleaner to recycle, although it is not recycled into the Java heap
The implementation of allocation and recycling is to call Unsafe’s allocateMemory and freeMemory, which are actually the system calls malloc and free
If you need to take the initiative to clean up, you need to use a
hack
method. You can refer to java. When all streams are closed, will an error be reported when deleting files on the hard disk? My answerIf it is a system cleanup, when it finds that the off-heap memory is insufficient, it will display the call
System.gc()
来清理堆外内存,可以通过添加-XX:+DisableExplicitGC
to overflow the off-heap memory