Here you can find the source of free(ByteBuffer byteBuffer)
public static boolean free(ByteBuffer byteBuffer)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import java.nio.ByteBuffer; public class Main { /**/*from ww w . j av a 2 s. c o m*/ * Try deallocate direct byte buffer, do nothing if buffer is not direct */ public static boolean free(ByteBuffer byteBuffer) { if (byteBuffer == null || !byteBuffer.isDirect()) { return false; } //call ((DirectBuffer)byteBuffer).cleaner().clean() by reflection try { Method getCleanerMethod = byteBuffer.getClass().getDeclaredMethod("cleaner"); getCleanerMethod.setAccessible(true); Object cleaner = getCleanerMethod.invoke(byteBuffer); if (cleaner != null) { Method cleanMethod = cleaner.getClass().getDeclaredMethod("clean"); cleanMethod.setAccessible(true); cleanMethod.invoke(cleaner); return true; } } catch (Exception e) { return false; } return false; } }