Thursday
03Dec2009
A great tip for diagnosing Java memory issues
Thursday, December 3, 2009 at 8:59AM My good friend (and creator of Apache Wicket) Jonathan Locke just gave me a great tip. I was aware of the jmap utility, but didn't know it could do this:
Just type:
jmap -histo:live <pid>
Where <pid> is the process id of a Java process, and it will dump out all objects, starting with whichever is taking up the most memory.
The handy thing is that the Java process doesn't need to have been started with any kind of special command line options, it will work with any running Java process.
I wish I knew this a few weeks ago while debugging a memory leak on a remote server...
Ian Clarke |
5 Comments | in
Java,
Programming
Java,
Programming 

Reader Comments (5)
If you have a fairly current JDK (and not just a JRE) in the relevant environment, you can also use VisualVM. It's essentially is nice GUI that runs on top of jmap, jstat, jinfo, and several other command line JVM tools. You can ask for a heap dump from any JVM visible to your current user and then browse it graphically. Considering that it's free, it's amazingly powerful.
Matt, thanks for the pointer. My main gripe with visualvm is that its very difficult to get it to connect to an application running on a remote server via an ssh tunnel (something I need to do very frequently).
Enterprise applications written in the Java language involve complex object relationships and utilize large numbers of objects. Although, the Java language automatically manages memory associated with object life cycles, understanding the application usage patterns for objects is important.
Hey Ian, Do you think we will ever see the adoption of a more feature rich server side language (like python) that can be embedded within html, like php? Why does php enjoy this unique position?
While working on a java outofmemoryerror problem, I took a systematic approach. In this approach, first step is identifying possible causes and then eliminating them step by step. In the last step where the complex part of memory leak is analysed, this tip is really important. Here is the complete article - http://www.myhomepageindia.com/index.php/2010/02/09/investigating-java-lang-outofmemoryerror.html.