search

Home  >  Q&A  >  body text

java - DirectBuffer的内存由操作系统分配,回收的时候呢?

ByteBuffer writeBuffer = ByteBuffer.allocateDirect(bytes.length);
大家讲道理大家讲道理2899 days ago284

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:58:21

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:58:21

    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

    reply
    0
  • Cancelreply