org.apache.commons.io.input

## Class ByteBufferCleaner

- java.lang.Object
- - org.apache.commons.io.input.ByteBufferCleaner

-     final class ByteBufferCleaner
      extends Object

  Cleans a direct `ByteBuffer`. Without manual intervention, direct ByteBuffers will be cleaned eventually upon garbage collection. However, this should not be relied upon since it may not occur in a timely fashion - especially since off heap ByeBuffers don't put pressure on the garbage collector.

  Warning: Do not attempt to use a direct `ByteBuffer` that has been cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned buffer will not be accessed anymore.

  See JDK-4724038

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ByteBufferCleaner()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static void` | `clean(ByteBuffer buffer)` Releases memory held by the given `ByteBuffer`.
    `(package private) static boolean` | `isSupported()` Tests if were able to load a suitable cleaner for the current JVM.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ByteBufferCleaner

          ByteBufferCleaner()

  - ### Method Detail

    - #### clean

          static void clean(ByteBuffer buffer)

      Releases memory held by the given `ByteBuffer`.
      Parameters:
        `buffer` - to release.
      Throws:
        `IllegalStateException` - on internal failure.

    - #### isSupported

          static boolean isSupported()

      Tests if were able to load a suitable cleaner for the current JVM. Attempting to call `ByteBufferCleaner#clean(ByteBuffer)` when this method returns false will result in an exception.
      Returns:
        `true` if cleaning is supported, `false` otherwise.