Handling garbage collection in Java program while producing a lot of garbage
<p>I have programmed a Jigsaw Puzzle which uses a BufferedImage for each piece. This is done because it has a specifc shadow and marking on it.
When I combine two pieces, I created a new BufferedImage, paint the two pieces on it, and throw all references to the old images away.
My problem is that during solving a puzzle with many pieces like 100 or so, the program seems to pile up more and more memory without running a garbage collection, and when it finally decides to clean up, it runs out of memory because the remaining free memory was too little for the garbage collection to run.
Is there any way I can tell the garbage collection to collect garbage more often and during a course of the game instead of waiting until the very last moment ?</p>
