ITPub博客

首页 > Linux操作系统 > Linux操作系统 > java 诊断内存泄露命令

java 诊断内存泄露命令

原创 Linux操作系统 作者:mscpx 时间:2010-03-23 18:18:25 0 删除 编辑
JConsole 
jmap  -comand pid   例如:
jmap -histo 1222
jmap -dump:file=dump.bin 1060

jhat  例如:
jhat -J-Xmx384m dump.bin

$ jmap -dump:file=dump.bin 1060
Dumping heap to /home/john/dump.bin ...
Heap dump file created
This 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博客 ” ,链接:https://blog.itpub.net/15742414/viewspace-630239/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-06-01

  • 博文量
    36
  • 访问量
    66464