In Java, you don't have true memory leaks like in C++. Java's garbage collection recovers memory so it doesn't have to be explicitly freed. However if you keep references to objects you don't need, you will waste memory. For example, if I have and keep adding items to the list, it will grow througout the life of the program. The JVM will not know to release the objects until I explictly null them out.
It recognizes scope, as soon as there is no reference to it left it should collect it. I seem to remember reading about an odd quirk with a collection (I think it was a collection) where objects in the collection don't have their resources reclaimed even when that part of the collection has been removed, but I'm not entirely sure, I'll try and find where I read that.
One important thing to remember about garbage collection (gc) is that you as a programmer can never force it to run. There's no way to ensure that at a particular point in your code all of the memory that you can no longer use will be cleaned up. Even if you have the following line of code in your program, gc isn't compelled to run:
Gc may run in this situtation, but the JVM may decide not to for some reason.
Tom Purl<br />SCJP 1.4
The moth suit and wings road is much more exciting than taxes. Or this tiny ad: