Java ByteBuffer Clean callCleaner(ByteBuffer byteBuffer)

Here you can find the source of callCleaner(ByteBuffer byteBuffer)

Description

Perform "GC" of byte buffer

License

Open Source License

Parameter

Parameter Description
byteBuffer byte buffer to be "Garbage Collected"

Exception

Parameter Description
NoSuchMethodException an exception
InvocationTargetException an exception
IllegalAccessException an exception

Declaration

public static void callCleaner(ByteBuffer byteBuffer)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;

public class Main {
    /**//from   w  w  w . j  a v a2  s  . c  o m
     * Perform "GC" of byte buffer
     * @param byteBuffer byte buffer to be "Garbage Collected"
     * @throws NoSuchMethodException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    public static void callCleaner(ByteBuffer byteBuffer)
            throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method cleanerMethod = byteBuffer.getClass().getMethod("cleaner");
        cleanerMethod.setAccessible(true);

        Object cleaner = cleanerMethod.invoke(byteBuffer);

        Method cleanMethod = cleaner.getClass().getMethod("clean");
        cleanMethod.setAccessible(true);
        cleanMethod.invoke(cleaner);
    }
}

Related

  1. cleanBuffer(final ByteBuffer bb)
  2. cleanDirectBuffer(ByteBuffer buffer)
  3. cleanMemBuff(MappedByteBuffer buffer)
  4. getCleanerMethod(final ByteBuffer buffer)