Reputation: 4205
I am trying to find memory leaks in a program I did not design (I'm new to the project). As it is quite a large program, I am having some trouble. I have tried a few profilers, and most of them hang or crash when attempting to follow the allocation stack trace to see which objects are taking up all of the memory.
I am running System.gc();
in a Thread and attempting to find out what exactly it is releasing/freeing. From the profiler, I can see that it is releasing, but I need to know what it is releasing.
Is there some way to get information at runtime from the garbage collector as to which objects it is releasing/freeing?
If not, or if this is a bad way to even think about trying to approach this, any other suggestions would be appreciated.
Upvotes: 0
Views: 129
Reputation: 853
i don't have the exact solution of which object will be realized by System.gc();
but JAVA provides built in GUI tool facility to JAVA monitoring and Management Console
you found jconsole in java/bin folder to run it: use command
cd $JAVA_HOME/bin
./jconsole
Upvotes: 0
Reputation: 533492
I would use a memory profiler to find a memory leak. You can start with VisualVM. this may find your problem, but if it doesn't try an evaluation version of a commercial profiler like YourKit.
These tools can not only tell you what is being discarded but where it is being creating in the first place. It has a graphical interface so you can see the biggest or most numerous.
Upvotes: 1
Reputation: 29814
My preferred way of finding memory leaks is triggering a heap dump by either waiting for it to happen (following an OOM) using -XX:+HeapDumpOnOutOfMemoryError
as a JVM launch parameter or 'on demand' using jsconsole/jmap.
Then run (the usually large) dump file through the excellent MAT http://www.eclipse.org/mat/
Upvotes: 2