Playing Quicktime movie and rapid memory increase (resolved)

I recently created a small project to test playing Quicktime movies, using the Quicktime for Java API, as a texture in OpenGL. The problem I have is that there is a very rapid increase in the amount of memory being used, and the amount used very rapidly passes by the 1GB limit.

To make sure that the issue wasn’t in the Quicktime code I ran it separately. In this scenario the memory usage did increase but much slower and inserting “System.gc()” into the loop actually helped it to stop increasing beyond a certain point and did not show the rapid growth that I saw in the case of OpenGL. Do note that I called all the same code that would be called by OpenGL class, minus any real drawing. I have tried to limit the amount of new objects being created in my loop to a maximum, but I just can’t work out what is going wrong.

Can anyone help?

FYI: MacOS X 10.4.3, Java 1.4.2, JOGL Build 2005-11-12 (my previous version of 2005-11-01 tried too)

Make sure that you reuse direct buffers. They are not always garbage collected in a timely manner and can run up the amount of memory used.

I am reusing all the buffers that I created. It was one of the first things I checked. I just had a quick look and I was allocating by buffer using

java.nio.ByteBuffer.wrap()

since I no longer need to wrap a byte array I have changed this to

java.nio.ByteBuffer.allocateDirect();

This seems to change nothing.

As an extra test I commented out the my call to create the movie and fetching the frames ( nextFrame(); ). This actually seems to slow down the rate of memory being used up (indicating my Quicktime code is partly in cause), but I don’t see it actually reaching a peak. I am going to leave my code running and see if it goes past the 1GB mark.

You’re creating a new OpenGL texture object each frame in your OpenGLMpeg.nextFrame() call. You should instead create one texture object in your init() method and re-use it each frame. The first frame you should call glTexImage2D to initialize the width and height of the image as you’re currently doing, but in subsequent frames you should use glTexSubImage2D for higher performance.

If anyone is interested I have made a copy of the source I am working on as an example project:

http://www.geocities.com/ajmas/MovieinOpenGL.zip

The project draws a movie on four walls of a "room’ and allows you to rotate the wall around the view point. So far I have only tested this on MacOS X. The memory usage is now stable. If anyone has any suggestions for improvement, I am all ears.