Memory leak with textures?

I'm wondering if I may have run into a potential memory leak while working with textures. Basically, I have a thread that generates cloud textures in real-time and stores the textures in an ArrayList. The textures are used in real-time, so the ArrayList acts as a buffer and never contains more than 20 textures.

As a test (and to reproduce the error), I currently have my thread just creating and deleting textures:

Texture cloudTex = generateCloudTexture();
Texture testTex = skyTexturePool.get(0);

After around 3,000 iterations, I receive the following error:

Exception in thread "Thread-9" java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(
at java.nio.DirectByteBuffer.<init>(
at java.nio.ByteBuffer.allocateDirect(
at com.jme.util.geom.BufferUtils.createByteBuffer(
at com.jme.util.TextureManager.loadImage(
at com.jme.util.TextureManager.loadTexture(
at com.jme.util.TextureManager.loadTexture(
at Utility.generateCloudTexture(

Is this a memory leak or am I doing something wrong?


Jme2 does not free native ressoures as far as I know, so genreating textures on the fly might not be a good idea.

(Why not passing the generate texture method a texture objects and modify it instead, but I'm not sure if that will really help, but i guess so)

But Prime is using TextureManager.deleteTextureFromCard(testTex);.

Wouldn't that delete it from OpenGL memory as well?

I still don't know what method to use to delete textures from OpenGL memory, it seems nobody really knows.