JFrame eating up memory, while few objects are to be painted

I have the following code and a tiny problem (on Linux that is, tried it yesterday on Windows, and it seemed to do the same).

The problem is that, as long as there are not many, say at least 5 Drawables in the array, the VM starts to eat up massive amount of RAM, quickly forcing the system to thrash on disk caching and eventually have me to quit Xorg.

As long as there are enough Drawables (they die after some time), the VM is happy, and everything works as intended.
So as long as you continually add Drawables to the scene, the memory usage does not peak.

What am I missing?

Sorry, if the code might be a bit lenghty…

code
moved to nopaste.
http://www.nopaste.com/p/ai9pma6fG

The problem is that you create a new back-buffer on each repaint:


        public void paint(Graphics g) {
                createBackBuffer();
                 
                  do {
 

Typically one would only want to do that if the size changed.

Also, I’d suggest to use BufferStrategy instead of VolatileImage
for implementing double-buffering.

Thanks,
Dmitri

Thanks a lot for your suggestion. That solved the problem.

Last time I implemented something like this, using VolatileImage was the fastest way I found to draw to the screen, so I figured I’d do it that way too this time.
Still bugs me, why the memory-eating didn’t occur when there where more than 4 items to be painted :smiley:

Thanks a bunch!