views:

98

answers:

2

Hello there,

I am using direct buffers (java.nio) to store vertex information for JOGL. These buffers are large, and they are replaced several times during the application life. The memory is not deallocated in time and I am running out of memory after a few replacements.

It seems that there is not good way to deallocate using java.nio's buffer classes. My question is this:

Is there some method in JOGL to delete Direct Buffers? I am looking into glDeleteBuffer(), but it seems like this only deletes the buffer from the video card memory.

Thanks

A: 

Deallocating a Direct Buffer is a job done by the garbage collector some time after the ByteBuffer object is marked.

You could try calling the gc immediatly after deleting the last reference to your buffer. At least there's a chance that the memory will be free'd a bit faster.

Andreas_D
By "calling the gc" you mean `System.gc()` I presume; it is indeed a long shot, as that call isn't guaranteed to really do anything. Make sure to set any reference to the direct buffer `= null` before calling that, or the GC will definitely think the buffer is still in use.
Ricket
+1  A: 

Direct buffers are tricky and don't have the usual garbage collection guarantees - see for more detail: http://download.oracle.com/javase/1.4.2/docs/api/java/nio/ByteBuffer.html#direct

If you are having issues, I'd suggest allocating once and re-using the buffer rather than allocating and deallocating repeatedly.

mikera