java - DirectBuffer的内存由操作系统分配,回收的时候呢?
大家讲道理
大家讲道理 2017-04-18 09:56:21
0
2
283
ByteBuffer writeBuffer = ByteBuffer.allocateDirect(bytes.length);
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
小葫芦

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

洪涛
  1. 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

  2. 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template