How to prevent Memory Leaks :
1
Steps
to find Memory Leaks
We
can prevent memory leaks by watching for some common problems. Collection
classes, such as hash tables and vectors, are common places to find the cause
of a memory leak. This is particularly true if the class has been declared
static and exists for the life of the application.
JProbe Memory
The JProbe Memory analysis tool enables you to:
·
Identify and resolve memory allocation issues. (For
eg. when in your code if you are doing explicity memory allocation, then the
tool would ensure that you are freeing up the memory also.)
·
Identify the underlying root cause of memory leaks
that can lead to instability and out-of-memory system crashes.
·
Identify the underlying root cause of excessive
garbage collection activity which can slow down the system performance. (For
example when memory is allocated and is not freed up, the garbage collection
would need to be run often)
JProbe
Memory Debugger helps you improve memory usage in your Java application by
identifying loitering objects and excessively allocated objects.
A
loitering object is an object that is determined to be reachable by the garbage
collector, but is no longer in use by your application. So if your program will
never use an object again, but you fail to remove the reference to the object,
the object will remain, or loiter, in memory indefinitely. This problem is
commonly referred to as ?unintentional object retention? or loitering objects.
Additionally, loitering objects can compound memory usage problems if that
object is acting as an anchor to other objects that would otherwise be marked
as unreachable by the garbage collector and therefore removed.
If
your program creates an excessive number of objects, the Java heap will become
larger, and garbage collection will take longer because there are more objects
to evaluate. A simple example would be a method that allocates a new temporary
object during each iteration of a loop, even though the object is never reused
and is no longer required when the loop terminates.
1
Steps
to find Memory Leaks
Step by step to find the
memory leaks using jprobe
Set
up license server as -
Select
the server to run under jprobe and to generate the jprobe script