Displaying video on texture speed problem and solutions failed

I’ve a project which I will post soon to Java.net . In this project I’m rendering video to texture . I use an own texture class, which is rendered with a method “public ByteBuffer getBuffer()” which returns the bytebuffer needed to feed glTexSubImage2D. My problem is :

I used PixelGrabber to obtain pixels of photograms. This method is extremely slow. Then I decided to have a BufferedImage. Then using createGraphics() , I render to this BufferedImage my video . Finally with getRaster().getData() I obtain the bytes needed for glTexSubImage. After doing this I call to dispose() method of Graphics2D()

When I run the demo, at the beginning, all is ok. Speed is multiplied by 3.5 or 4 factor. But , after 5 or 6 seconds an error like this is thrown

Exception in thread “Image Fetcher 2” java.lang.OutOfMemoryError: Java heap space
at java.awt.image.D […]

Exception in thread “Image Fetcher 3” java.lang.OutOfMemoryError: Java heap space
at java.awt.image.D […]

Exception in thread “Image Fetcher 0” java.lang.OutOfMemoryError: Java heap space
at java.awt.image.D […]

Exception in thread “Image Fetcher 1” java.lang.OutOfMemoryError: Java heap space
at java.awt.image.D […]

What can I do?

I’ve tried to use TextureRenderer but I get the same error. What am I doing wrong??

You’ll need to use a profiler to see where your heap space is going at the point the OutOfMemoryError is being thrown. Almost undoubtedly you’re accidentally holding on to older disposed BufferedImages somewhere.