I hope this is not too long winded... I have been having a problem with an applet of mine for quite some time now. There are workarounds, but I find them distasteful. I would rather find the root of the problem. The applet is basically a glorified picture viewer which cycles through a series of photos based on user input. My problem is that after 40 pics or so, I get an
OutOfMemory heap error. I'm using the getImage() method to load in the pics.
They're loaded on demand and copied to a (once new'd BufferedImage). Then I use the buffered image for display and control. It all happens in an updatePhoto() method, and goes something like this: (More pseudo code than actual code)
public void updatePhoto(name)
tmpImage = getImage(URL, name);
Graphics gTmp = currentImage.createGraphics(); // currentImage is the BufferedImage already created
gTmp.drawImage(tmpImage, 0, 0, this);
This all works quite well, until the number of different photos reaches the critical number.
My biggest question is: Does getImage() cache the images onto the heap? This has been my suspicion all along because if I force the applet to handle fewer than the critical number of photos, it will go on forever. If the answer is no, they don't get cached, then I can focus my efforts elsewhere. If the answer is yes, is it possible to remove them from the heap? I can't imagine those who know far more than I would stick me with image data I might need only once.
I am assuming that tmpImage will no longer be valid upon exit since it's a local variable and will be "collected". I have tried forcing garbage collection with no sucess.
Thanks for any help and insight