jLuger.de - Fixing memory leaks in Java

The last days at the office I've spent hunting a memory leak in a Java Swing Client. Here I want to describe the experiences I've made.

First realize how to get memory leaks:
A memory leak is the behavior of an application to consume constantly more and more memory. As all machines have an limited amount of RAM you application will crash with an OutOfMemoryError. Normally the garbage collector will search for dead object and release their memory. But when all objects are referenced (directly or indirectly through other objects) by a root set (e.g. static variable, or reference from the stack) no memory will be released.
The easiest way in Java to create such a leak is to have a list and a loop where you add values to the list but you have no place in your code where to take values out of the list. The loop even may be code that is regularly called by the user. A typical candidate for this is adding a event listener to a frame on a button click but the frame is never garbaged collected.

The tools you could use:
The jdk includes some tools you could use to profile your application for memory leaks.
The tools have pretty good help pages and there are blog entries describing how to use them. So I will not go into detail.

Lessons learned: