Java程序内存分析:JMap与Eclipse Memory Analyzer
当程序中内存使用过多,或者存在内存泄露时,经常会报OutOfMemory错误。很多时候,尤其是在生产环境中,不得不马上重启服务,导致现场丢失,无法查找问题所在。
其实jdk中自带了很多分析监控工具,jmap就是其中之一。
当程序出现问题,先不要停止服务,先用ps看一下java的pid, 然后运行命令将内存导出来:
/usr/local/jdk1.6.0_20/bin/jmap -dump:format=b,file=/dir/heap.bin |
这个heap.bin就是当前内存中的内容。如果很大,可以用gzip压缩一下。
此时就有很多工具来分析heap.bin了,我使用的是eclipse memory analyzer 。具体使用方法比较简单,里面可以看到每个对象的占用情况。
上两个我的程序出问题时的截图:
通过这两个图,很容易就定位出了Cache里的filter变量有问题。
我的实践中,改进之后,内存占用从1G下降到了60多M。
原创文章如转载,请注明:转载自CODIGG [ http://www.codigg.com/ ]
本文链接地址:http://www.codigg.com/2010/07/java-jmap-eclipse-memory-analyzer/




二月 21st, 2011 at 22:47
sFeLSsqX
[回复]
六月 3rd, 2011 at 15:40
3458283 beers on the wall.
[回复]
六月 3rd, 2011 at 15:40
1906845 beers on the wall.
[回复]
一月 14th, 2012 at 13:06
Thanks for all of the labor on this blog. My daughter take interest in managing investigation and it’s really obvious why. A lot of people learn all about the compelling way you render practical tips and hints on your web site and as well increase contribution from website visitors on that area of interest and our own child is undoubtedly being taught a lot. Take advantage of the remaining portion of the year. You’re conducting a great job.
[回复]
一月 22nd, 2012 at 22:55
Sharing some thing is better than keeping up-to our self, therefore the YouTube video that is posted at this time I am going to share by means of my family and friends.
[回复]
一月 22nd, 2012 at 23:47
This piece of writing about SEO is really good one, and the back links are actually very helpful to promote your web site, its also referred to as Search engine optimization.
[回复]
一月 25th, 2012 at 06:52
˙ţC
[回复]
一月 29th, 2012 at 19:15
I simply had to thank you so much once again. I am not sure the things I would’ve tried without the actual hints discussed by you on such question. It became an absolute fearsome situation in my opinion, but taking note of this expert manner you dealt with that forced me to jump over delight. I’m just thankful for the support and even pray you really know what an amazing job you have been accomplishing educating men and women via your web page. More than likely you haven’t got to know all of us.
[回复]
一月 31st, 2012 at 10:06
May I simply say what a relief to find someone who genuinely understands what exactly theyre talking about on the net. You definitely know how to deliver a concern to light plus makes it critical. A lot more folks need to see this as well as know this unique aspect of the article. I can’t imagine you’re not popular simply because you without doubt possess the Skill set.
[回复]
二月 3rd, 2012 at 01:44
Very useful publish here. Thanks for sharing your knowledge with me. I will certainly be back again.
[回复]
二月 6th, 2012 at 06:38
I’ll come back as soon as once again inside the potential to examine out your blogposts down the road.
[回复]
二月 6th, 2012 at 10:45
Have you ever thought about adding a little bit more than just your articles? I mean, what you say is fundamental and everything. However imagine if you added some great images or videos to give your posts more, “pop”! Your content is excellent but with pics and clips, this blog could definitely be one of the best in its niche. Fantastic blog!
[回复]
二月 6th, 2012 at 13:23
Hi persons I merely wanted to stop by your site as well as check in so I could drop my back link. I wish that you find our composition as beneficial as I did yours! We are a hands on sort of operation, so if you have any inquiries concerning our products satisfy let us recognize!
[回复]
二月 6th, 2012 at 14:13
Hi there would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot faster then most. Can you suggest a good internet hosting provider at a fair price? Kudos, I appreciate it!
[回复]
二月 6th, 2012 at 14:28
Even if you have never looked at it but have been tempted to do so, you must still seek help so that it doesn’t progress.
[回复]
二月 6th, 2012 at 17:46
Heya! Stunning article! Now i’m a usual visitor to your site (much more like addict
) of the website however I had a challenge. I am just never absoluetly certain whether its the right web site to ask, but you have no spam comments. I receive comments almost daily. Would you help me? Thanks much!
[回复]
二月 7th, 2012 at 02:51
Hello, you used to write great, but the last several posts have been kinda boring… I miss your great writings. Past few posts are just a bit out of track! come on!
[回复]
二月 7th, 2012 at 07:10
theres still loads stunning free dating sites that are available to sign up
[回复]
二月 7th, 2012 at 07:49
I would like to take the opportunity of thanking you for the professional instruction I have enjoyed visiting your site. We’re looking forward to the particular commencement of my university research and the overall groundwork would never have been complete without checking out your blog. If I might be of any help to others, I’d personally be pleased to help via what I have gained from here.
[回复]
二月 7th, 2012 at 08:47
Oh my goodness! a tremendous article dude. Thanks Nonetheless I’m experiencing difficulty with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anyone who knows kindly respond. Thnkx
[回复]
二月 7th, 2012 at 12:34
I like what you guys are up also. Such intelligent work and reporting! Keep up the superb works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my site
.
[回复]
二月 7th, 2012 at 13:15
You have great info on this site… I think it’s great! Thanks!
[回复]
二月 7th, 2012 at 13:48
Fascinating thoughts the following. I appreciate you taking the time to share with you them with us all.
[回复]
二月 7th, 2012 at 14:37
Thanks for all your efforts that you have put in this. Very interesting information. “There is still no cure for the common birthday.” by John Glenn.
[回复]
二月 7th, 2012 at 17:28
I appreciate all the work you’ve put into your website! I’m going to Tweet this out to my followers… Definitely worth sharing!
[回复]