How to load many textures without leaking memory?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to load many textures without leaking memory?

Phate666
Hi,
In our application we need to load new textures every second (or even more often).
The problem is that native memory (not java heap) keeps increasing without bounds.
Things I already tried:

texture.destroy(gl);
texture = TextureIO.newTexture(new File(texturePath), true);

and

texture.updateImage(gl, TextureIO.newTextureData(Test.glp,
                                                new File(texturePath), true, null));

Both code fragments gets executed every time the texture needs an update.
Any idea how to fix this memory leak?
Reply | Threaded
Open this post in threaded view
|

Re: How to load many textures without leaking memory?

gouessej
Administrator
Hi

You should use GL.glDeleteTextures() and Texture.getTextureObject(GL). If the problem persists, you will have to write a bug report. Texture.destroy(GL) should work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to load many textures without leaking memory?

Phate666
I actually just found a solution, I just had to add a manually System.gc() call after each texture.destroy(gl), then the native memory stays low.
Not sure if this behaviour is intended, but it works.
Reply | Threaded
Open this post in threaded view
|

Re: How to load many textures without leaking memory?

gouessej
Administrator
Ok I know a better workaround, it comes from the laziness of the virtual machine to reclaim unused native memory. Get the buffer of the texture data, get its cleaner and call Cleaner.clean(). Using System.gc() may have some unwanted effects...
Julien Gouesse | Personal blog | Website