Hi,
well don't take my
word for it but this is what I seem to remember after reading some books. The garbage collector really isn't that smart although I'm sure it's been made better with every version of the JDK. You could for instance try to use the new "hotspot" VM that comes with the 1.3 JDK.
The garbage collector is pretty much like a daemon
thread,working in the background and doing it's work,freeing up memory by getting rid of objects that aren't referenced anymore, while the processor is sitting idle for a split second. If the processor is working all the time there will not be any garbage collected because the gc has the lowest priority, so this will go on till the memory is full and the garbage just has to be collected or nothing will go anymore..at that point the garbage collector starts working no matter all the other processes with higher priorities.
There are situations though that stuff doesnt get gc'd, for instance if it's not explicitly made by the keyword "new". I think this could go for images that are painted on your screen. To free up the memory that these take up and get rid of the images you explicitly need to write a method for just that. C++ has like a "destructor" I read but
Java doesn't so it's up to you to do that.
As far as i can tell there isn't much more you can do though than call System.gc . This
you should do after all the objects are created and discarded though or else it won't call all the finalizers. Maybe you could also add another line after System.gc using System.runFinalization().
Good luck
)
Patrick