Login  Register

Re: How to delete direct Buffers?

Posted by Sven Gothel on Nov 27, 2014; 8:34pm
URL: https://forum.jogamp.org/How-to-delete-direct-Buffers-tp4033631p4033659.html

On 11/27/2014 03:30 PM, Vasilij [via jogamp] wrote:

> I have to correct myself, i delete DirectBuffers not exacltly same as in
> https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/util/BufferUtils.java#L1307
>
> I do not use "Method" and ".invoke()"
> I do it like this:
>
> Cleaner cleaner;
> if(vertices.isDirect())
>                                 {
>                                         ByteBuffer abc = (ByteBuffer)(
> (DirectBuffer)vertices ).attachment();
>                                         cleaner = ((DirectBuffer)abc).cleaner();
>
>                                         if(cleaner != null)
>                                         {
>                                                 cleaner.clean();
>                                         }
>
>                                         cleaner = null;
>                                         abc = null;
>                                         vertices = null;
>                                
> }
>
> Are this two options very different?
I have also employed sun.misc.Cleaner methods
in GlueGen's MappedByteBufferInputStream:
  com.jogamp.common.nio.MappedByteBufferInputStream

Intent is to use memory mapped NIO files
as InputStream and OutputStream while overcoming
the NIO buffer 'int' address range.

See unit tests:
  com.jogamp.common.nio.TestByteBufferInputStream
  com.jogamp.common.nio.TestByteBufferOutputStream
  com.jogamp.common.nio.TestByteBufferCopyStream

Result of using the 'cleaner' depends on the implementing platform,
however, 'htop' and other heap monitors show that the
mapped memory is released.

Hope it helps a bit.

~Sven



signature.asc (828 bytes) Download Attachment