learning sites for fixing java memory leaks

笑着哭i 提交于 2019-12-07 14:49:50

问题


What would be the best places to learn fixing a java memory leak ? I have been trying to find good resource over the NET but to my disappointment, I find toy examples being discussed. I am also able to troubleshoot small toy dumps but the real world application dumps are more challenging and give little clue.

I have tried tools like Jhat, JMap, VisualVM and MAT.

what would be the best place to learn about fixing Java memory leaks ? suggestion of a book is also welcome.

thanks in advance.


回答1:


Have you tried searching the internet? There are many examples. A good search engine will sort them by relevance.




回答2:


There are many kind of memory leaks but in practice the following strategy gives good results (Disclaimer: I'm showing screen shots from JProfiler, because my company develops it):

1. Check the biggest objects

"Biggest objects" retain a lot of memory that nobody else is holding on to. In JProfiler, they can be found in the "Biggest objects" view of the heap walker. This often happens with caches.

2. Check classes with a lot of instances

Sometimes, the references are more intricate and the biggest objects do not give a clue. Classes with a lot of instances can be checked for their incoming references. First, it is helpful to look at cumulated references, to separate valid reference chains from suspicious reference chains.

Also, checking where instances have been allocated (as opposed to how they are referenced) can often give an insight on what is going on.

Often, this is a multi-step process, selecting reference chains, allocation spots, or making selections based on the contents of objects.

3. Search for paths to GC roots

If that still does not provide a clue, you can select single objects and show their reference chains that lead to garbage collector roots. It helps a lot of you were able to narrow down an object set of suspicious objects before trying to to that, otherwise you may have a lot of candidates.

There is also a screen cast on this topic.



来源:https://stackoverflow.com/questions/11727183/learning-sites-for-fixing-java-memory-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!