How does MappedByteBuffer get garbage-collected?

418 Views Asked by At

From the Java docs,

The contents of direct buffers may reside outside of the normal garbage-collected heap, and so their impact upon the memory footprint of an application might not be obvious

Also from the Java docs,

MappedByteBuffer: A direct byte buffer whose content is a memory-mapped region of a file.

and

A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected.

I believe that off the heap memory allocations cannot be garbage-collected by the GC. In this case, these statements make me curious about memory management of a MappedByteBuffer. What happens if the direct ByteBuffer backing a MappedByteBuffer sits outside the normal heap?

0

There are 0 best solutions below