pratap
Answered On : May 25th, 2006
You may use "JProbe Memory debugger" tool to identify memory leaks in your code.
Thanks,
Pratap
Login to rate this answer.
To reduce possibility of memory leaks, following things should be kept in mind.
Try to avoid long recursive loops in the code. This leads to an OutOfMemoryError.
Avoid collections as static members of a class. If so, carefully manage removals and additions to the Collection. If the collection continues adding members without removing them, it might lead to a leak. Static members persist throughout the life of the program. A static collection will keep references to objects, whether you are using it or not. So the garbage collector might miss collecting the unused contents of the collection.
Avoid populating the HttpSession with too much data. Session persists in the system as long as the user is online, and it might get filled up fast. Additions and removals in the session should be checked.
If you are using AWT/Swing components, call dispose() to kill the windowing component completely.
Check your native code for memory leaks, if you are calling C/C++ code from Java using JNI.
There are other things too, to take care of, but these are the most important ones.

2 Users have rated as useful.
Login to rate this answer.