Re: JOGL OpenGL ES error in NetBeans
Posted by jmaasing on Oct 27, 2015; 2:10pm
URL: https://forum.jogamp.org/JOGL-OpenGL-ES-error-in-NetBeans-tp4035582p4035614.html
Java does release native buffers back when the Java Buffer object is garbage collected. So using NIO buffers is not automatically a memory leak.
But there are 2 catches:
Given that a NIO buffer is collectable (i.e. the java side has no more references to a buffer), will the GC collect it? Probably not since the buffer object on the heap is quite small so the GC usually does not bother, it can reclaim more memory by collecting other "dead" references so it may prioritize other things. Remember that the native memory is off-heap so not visible to the GC. So it is better that your code knows about the native memory allocations and clean them up itself.
The other catch is that texture memory is probably uploaded to the graphics card to be of any use. Since graphics memory is a scarce resource you really want to manage that yourself since only your code knows what textures are of interest at a given time. To inform the OpenGL-driver that you are done with a texture and it can be destroyed you must do so on a thread with an active GL Context and the JVM does not know anything about that so it is up to user code to manage that.
So it all boils down to what gouessej said :-)