public static void destroyDirectByteBuffer(ByteBuffer toBeDestroyed)
    throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
    SecurityException, NoSuchMethodException {

    Preconditions.checkArgument(toBeDestroyed.isDirect(), "toBeDestroyed isn't direct!");

    Method cleanerMethod = toBeDestroyed.getClass().getMethod("cleaner");
    cleanerMethod.setAccessible(true);
    Object cleaner = cleanerMethod.invoke(toBeDestroyed);
    Method cleanMethod = cleaner.getClass().getMethod("clean");
    cleanMethod.setAccessible(true);
    cleanMethod.invoke(cleaner);
  }
DirectByteBuffers are garbage collected by using a phantom reference and a reference queue.
Every once a while, the JVM checks the reference queue and cleans the DirectByteBuffers.
However, as this doesn't happen immediately after discarding all references to a
DirectByteBuffer, it's easy to OutOfMemoryError yourself using DirectByteBuffers. This function
explicitly calls the Cleaner method of a DirectByteBuffer. The DirectByteBuffer that will be
"cleaned". Utilizes reflection.
hbase-server/src/main/java/org/apache/hadoop/hbase/util/DirectMemoryUtils.java