Tss Translation: common Java memory problems Part 1
Http://www.theserverside.com/news/thread.tss? Thread_id = 62217
Http://blog.dynatrace.com/2011/04/20/the-top-java-memory-problems-part-1/
Memory and garbage collector have always been one of the most noteworthy issues in Java applications. When we talk about the JVM memory collection mechanism in Java, I am afraid most people will be confused about the GC garbage collection mechanism. Michael Kopp of dynatrace also shares the same feeling, but he lists the main causes of Java Memory leakage.
1, Thread Local Variable Thread Local Variables
It is easy to use the thread pool, and the heap dump is easy to locate the problem;
2, Mutable static fields and collections
It is easy to avoid this situation. A good enough tural rule is not to use
Mutable static objects at all, most of the time there is a better alternative.
3, Loop and complex bidirectional references circular and complex bi-directional references
The other party provides a classic example:
org.w3c.dom.Document doc =
readXmlDocument();
org.w3c.dom.Node child =
doc.getDocumentElement().getFirstChild();
doc.removeNode(child);
doc = null;
4, JNI Memory leakage JNI memory leaks
I'm not using much.
5, Class
Incorrect equals/hashcode implementation
Such classes are prone to problems when hashmap is used.
The way to avoid this is to do a test like this tool: http://code.google.com/p/equalsverifier/
6, Memory leakage caused by class loaders
The layer of Class Loader is relatively low, which is usually common in application servers and osgi containers.
Maybe the reply is more exciting. We have combined 1, 2, and 6:
Static threadlocal mywrapper =
New threadlocal (){
Notthreadsafeobject initialvalue (){
Return new notthreadsafeobject ();
}
}
...
Mywrapper. Get (). somemethod ()
...
More detail at http://www.szegedi.org/articles/memleak.html
How to Use dynatrace:
Http://blog.dynatrace.com/2011/04/13/application-performance-monitoring-in-production-a-step-by-step-guide/