$ jmap -dump:file=dump.bin 1060 Dumping heap to /home/john/dump.bin ... Heap dump file createdThis will generate a binary dump of the JVM heap in a file called dump.bin.
Another option if you suspect memory leaks on a production is to start your application with the -XX:+HeapDumpOnOutOfMemoryError command-line option. This won't prevent any memory leaks, but it will cause the VM to generate a heap dump, enabling you to analyze the heap afterward, using jhat or some other tool.
Now we need to be able to inspect the contents of the heap dump. This is where jhat comes into action. It analyzes a binary heap dump, and starts up a web server on a local port where you can interactively explore and query the Heap Dump. You run it as follows (the -J-Xmx384m allows a maximum heap space of 384 MB; this option is not mandatory, but jhat is fairly demanding in resources, so you should give it a fair bit of memory to work with):
$ jhat -J-Xmx384m dump.bin
Reading from dump.bin... Dump file created Tue Dec 26 13:20:27 NZDT 2006 Snapshot read, resolving... Resolving 949898 objects... Chasing references, expect 189 dots............................................. ................................................................................ ................................................................ Eliminating duplicate references................................................ ................................................................................ ............................................................. Snapshot resolved. Started HTTP server on port 7000 Server is ready.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15742414/viewspace-630239/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15742414/viewspace-630239/