public class DirectByteBufferUtils extends Object
ByteBuffer
s.
The release method was taken from research in the following places:
Constructor and Description |
---|
DirectByteBufferUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
release(Buffer bb)
Direct
ByteBuffer s are stored in system memory, and released when garbage collection occurs
and the buffer is deemed to be unreachable, following vanilla garbage collection procedures. |
public static final Logger LOGGER
public static void release(Buffer bb)
ByteBuffer
s are stored in system memory, and released when garbage collection occurs
and the buffer is deemed to be unreachable, following vanilla garbage collection procedures. At that
point, a special finalizer, "Cleaner" runs to de-allocate the system memory (and in the case of
MappedByteBuffer
s, unmap the file).
However, if garbage collection does not occur, the system memory remains taken, and the MappedByteBuffer
(if applicable) remains mapped, meaning system level operations cannot occur in other processes.
This method seeks to release a direct ByteBuffer
early by calling well known reflective code
in a best-attempt fashion. In the case that this reflective code is not present, the method
finishes with a log message, and normal Java practice takes over; i.e. the buffer is not released
and if it's a MappedByteBuffer
the file is not unmapped, until later GC occurs or the
JVM is terminated.bb
- NullPointerException
- If bb is null.IllegalArgumentException
- If bb is not a "direct" ByteBuffer
Copyright © 2005–2018 jthink.net. All rights reserved.