Best way to find memory leak

L

lordy

I've got a big app and I need a tool that can quickly help me locate a
memory leak. Luckily, the app can run in a fast mode (60x), so
one option is to run it with JRocket and use the Leak Detector.
(The developer license allows me to run it for one hour, which is enough
time for the leak to appear running in fast mode).

Are the any other neat tools for this.

Thanks.
Lordy
 
L

lordy

Valgrind on Linux. There is a note in the FAQ about dynamically generated
code and a flag.

Thanks, but I think this only works at the System heap memory level. I
want to find Java objects that are not getting GC'ed and why..

Cheers,
Lordy
 
N

Nick Vatamaniuc

Lordy,

Please see this the GC Portal on java.sun.com.
http://java.sun.com/developer/technicalArticles/Programming/GCPortal/
There is way to run the JVM with the verbose GC options for example:
-verbose:gc
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
There you will also find references to visualgc and jvmstat
http://java.sun.com/performance/jvmstat/visualgc.html
http://java.sun.com/performance/jvmstat/

A quick and dirty way is to test the limits of your program is to
stress test it. For example instead of having it run for 10 minutes and
creating 1000 objects as normally does, have it run for 5 hours and
create 1000000 objects and just look at your memory. It is just sort of
a real-life testing. If your program works will under x100 the 'normal'
conditions, it is probably 'good enough'. In other words you could
spend 2 days finding 'leaks' and tunning the GC only to get a tiny
performance boost - it might not be worth it altogether, but you would
know better of course...

Hope this helps,
Nick Vatamaniuc
 
P

pranshu

Hi Lordy,
If you know there is a memory leak and have the steps to reproduce it,
then you have good tools. Essentially, you need to look for profilers
which can do memory profiling ( most of them do) - like Jprobe which I
have used and found to be good.
You have to setup the application to profile using the profiler,
execute the steps for the first time manually,call GC , take a
snapshot of memory, execute the same steps for the second time
manually, call gc again and take a snapshot again. Now if you diff the
two snapshots you will know which are the culprit objects. The first
step is necessary so that you donot count cached objects or the ones
you want to live in memory.

If you donot know if there is a memory leak, then it will be best to do
a performance test by recording the frequently used scenarios and
executing a load test over time.

You will need to look at the memory utilization of the JVM and see if
it is consistently growing with time. It sometimes help if you can code
a JSP which explicitly calls GS and invoke that once in a while - just
so that you know which points to take in the graph.

Regards
Pranshu
 
L

lordy

Lordy,

Please see this the GC Portal on java.sun.com.
http://java.sun.com/developer/technicalArticles/Programming/GCPortal/
There is way to run the JVM with the verbose GC options for example:
-verbose:gc
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
There you will also find references to visualgc and jvmstat
http://java.sun.com/performance/jvmstat/visualgc.html
http://java.sun.com/performance/jvmstat/

A quick and dirty way is to test the limits of your program is to
stress test it. For example instead of having it run for 10 minutes and
creating 1000 objects as normally does, have it run for 5 hours and
create 1000000 objects and just look at your memory. It is just sort of
a real-life testing. If your program works will under x100 the 'normal'
conditions, it is probably 'good enough'. In other words you could
spend 2 days finding 'leaks' and tunning the GC only to get a tiny
performance boost - it might not be worth it altogether, but you would
know better of course...

Hope this helps,
Nick Vatamaniuc

Thanks for that. I did observe the lean during a stress test. I just
wanted a quick way of pinpointing the hanging references. It turns out
that some resultSets were not getting closed. Found using JRockit
memory leak tools.

Lordy
 
L

lordy

Hi Lordy,
If you know there is a memory leak and have the steps to reproduce it,
then you have good tools. Essentially, you need to look for profilers
which can do memory profiling ( most of them do) - like Jprobe which I
have used and found to be good.
You have to setup the application to profile using the profiler,
execute the steps for the first time manually,call GC , take a
snapshot of memory, execute the same steps for the second time
manually, call gc again and take a snapshot again. Now if you diff the
two snapshots you will know which are the culprit objects. The first
step is necessary so that you donot count cached objects or the ones
you want to live in memory.

Useful. Thanks.
You will need to look at the memory utilization of the JVM and see if
it is consistently growing with time. It sometimes help if you can code
a JSP which explicitly calls GS and invoke that once in a while - just
so that you know which points to take in the graph.

Yup. Did that.

Lordy
 
I

IchBin

lordy said:
Windows only :(.

Lordy

How about the java_home\bin\jconsole.exe

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top