@Override
    public void destroyDirectBuffer(Buffer toBeDestroyed) {
        try {
            if (freeMethod != null) {
                freeMethod.invoke(toBeDestroyed);
            } else {
                //TODO load the methods only once, store them into a cache (only for Java >= 9)
                Method localCleanerMethod;
                if (cleanerMethod == null) {
                    localCleanerMethod = loadMethod(toBeDestroyed.getClass().getName(), "cleaner");
                } else {
                    localCleanerMethod = cleanerMethod;
                }
                if (localCleanerMethod == null) {
                    Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE,
                            "Buffer cannot be destroyed: {0}", toBeDestroyed);
                } else {
                    Object cleaner = localCleanerMethod.invoke(toBeDestroyed);
                    if (cleaner != null) {
                        Method localCleanMethod;
                        if (cleanMethod == null) {
                            if (cleaner instanceof Runnable) {
                                // jdk.internal.ref.Cleaner implements Runnable in Java 9
                                localCleanMethod = loadMethod(Runnable.class.getName(), "run");
                            } else {
                                // sun.misc.Cleaner does not implement Runnable in Java < 9
                                localCleanMethod = loadMethod(cleaner.getClass().getName(), "clean");
                            }
                        } else {
                            localCleanMethod = cleanMethod;
                        }
                        if (localCleanMethod == null) {
                            Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE,
                                    "Buffer cannot be destroyed: {0}", toBeDestroyed);
                        } else {
                            localCleanMethod.invoke(cleaner);
                        }
                    } else {
                        Method localViewedBufferMethod;
                        if (viewedBufferMethod == null) {
                            localViewedBufferMethod = loadMethod(toBeDestroyed.getClass().getName(), "viewedBuffer");
                        } else {
                            localViewedBufferMethod = viewedBufferMethod;
                        }
                        if (localViewedBufferMethod == null) {
                            Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE,
                                    "Buffer cannot be destroyed: {0}", toBeDestroyed);
                        } else {
                            // Try the alternate approach of getting the viewed
                            // buffer
                            // first
                            Object viewedBuffer = localViewedBufferMethod.invoke(toBeDestroyed);
                            if (viewedBuffer != null) {
                                if (viewedBuffer instanceof Buffer) {
                                    destroyDirectBuffer((Buffer) viewedBuffer);
                                }
                                // Else nothing to do, we may be on android which has an
                                // internal system for freeing direct buffers
                            } else {
                                Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE,
                                        "Buffer cannot be destroyed: {0}", toBeDestroyed);
                            }
                        }
                    }
                }
            }
        } catch (IllegalAccessException
                | IllegalArgumentException
                | InvocationTargetException
                | SecurityException ex) {
            Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
        }
    }
This function explicitly calls the Cleaner method of a direct buffer.

@param toBeDestroyed
           The direct buffer that will be "cleaned". Utilizes reflection.
jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java