Login  Register

DirectBuffer deallocation

Posted by elect on Jan 12, 2016; 9:27am
URL: https://forum.jogamp.org/DirectBuffer-deallocation-tp4035990.html

I need definitely to find a way to deallocate this damn direct buffers

I tried with

((DirectBuffer) directBuffer).cleaner().clean();

But I get a null exception, if I expand the function

try {
            //        ((DirectBuffer) directBuffer).cleaner().clean();
            if(!directBuffer.isDirect()) {
                return;
            }
           
            Method cleanerMethod = directBuffer.getClass().getMethod("cleaner");
            cleanerMethod.setAccessible(true);
            Object cleaner = cleanerMethod.invoke(directBuffer);
            Method cleanMethod = cleaner.getClass().getMethod("clean");
            cleanMethod.setAccessible(true);
            cleanMethod.invoke(cleaner);
           
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException
                | IllegalArgumentException | InvocationTargetException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }

I receive a null at this line:

            Method cleanMethod = cleaner.getClass().getMethod("clean");

Why?

@Julien your class  can easily be modified to accept also direct short/int/float buffers?