Tuesday, May 04, 2010

Memory Profiling Java Application

In continuation to the last post on Jboss Profiler, thought of sharing this simple and elegant memory profiler that ships with your JSDK (jmap)...

  • To know the # of instances & type of objects in the heap in a simple and quick way,
  1. jmap -histo > snapshot1.txt
  2. Sample Output:
num #instances #bytes class name
--------------------------------------
1: 5555 6013016 java.util.Hashmap
2: 103 482888 org.apache....
3: 2000 334928 org.jboss...
4: 1280 274976 org.spring...
  • To troubleshoot a memory leak, do the above command multiple time and observe the snapshot.
  • jconsole is good enough, but this give a verbose details on the memory.
  • jhat is cool utility to browse the object topology over http on a specific port for analysis.

No comments: