Java : Get heap dump without jmap or without hanging the application

Viewed 19316

In few circumstance, our application is using around 12 GB of memory. We tried to get the heap dump using jmap utility. Since the application is using some GB of memory it causes the application to stop responding and causes problem in production.

In our case the heap usage suddenly increases from 2-3 GB to 12GB in 6 hours. In an attempt to find teh memory usage trend we tried to collect the heap dump every one hour after restarting the application. But as said since using the jmap causes the application to hang we need to restart it and we are not able to get the trend of memory usage.

Is there a way to get the heap dump without hanging the application or is there a utility other than jmap to collect heap dump.

Thoughts on this highly appreciated, since without getting the trend of memory usage it is highly difficult to fix the issue.

Note: Our application runs in CentOS.

Thanks, Arun

5 Answers

A heap dump analyzed with the right tool will tell you exactly what is consuming the heap. It is the best tool for tracking down memory leaks. However, collecting a heap dump is slow let alone analyzing it.

With knowledge of the workings of your application, sometimes a histogram is enough to give you a clue of where to look for the problem. For example, if MyClass$Inner is at the top of the histogram and MyClass$Inner is only used in MyClass, then you know exactly which file to look for a problem.

Here's the command for collecting a histogram.

jcmdpidGC.class_histogram filename=histogram.txt

Related