Login  Register

JOGL Texture Memory Management

Posted by r.jaoui on Mar 24, 2021; 11:19am
URL: https://forum.jogamp.org/JOGL-Texture-Memory-Management-tp4041055.html

Hello !

I’m currently writing a 2D Graphics engine, and in a few occasions I seem to get memory leaks when working with textures. Here is my setup :

- Images are stored as a OpenGL Texture (no the JOGL Texture implementation) coupled with a pixel array (the array can be loaded from the texture, and at a later date the texture can be updated with the pixels)

- For a few texture rendering purposes, a single general Texture Rendering FBO is statically created, and is then used with glFramebufferTexture2D each time I want to modify a texture.

- For now, in the finalize method, I delete the specific texture linked with this Image (and the console shows that textures are deleted). I also tried to create a close function myself, and the leak is still present.

- The specific code I’m trying to run is to clear the screen and draw an image (loaded from a file in init), then gather the whole panel as a texture (using glReadPixels to get the pixels and then loading them onto a texture). This seems to be the line that causes the leak, but also just creating an image (not even loading it) on each frame (and although it is destructed at the end of the frame) still causes a leak.

- When displaying the Texture IDs that are being destructed at each frame, I get something like this :

and at this point the memory used by the programs can be in the Gigabytes…

I am currently not using the Texture object (would it make a difference ?). I wanted to know how JOGL's texture memory management worked (are the textures deallocated on glDeleteTextures ? Why do the texture indices keep increasing even though the textures are deleted ? Is there a specific way to make sure that the used memory doesn't get out of control ?)

Thanks !