Original article:Http://www.theserverside.com/news/thread.tss? Thread_id = 62217
Http://blog.dynatrace.com/2011/04/20/the-top-java-memory-problems-part-1/
The memory and garbage collector are alwaysJavaOne of the most noteworthy issues for applications. When weJavaYesJVMWhen talking about the memory collection mechanism, I am afraid most peopleGCThe mechanism of garbage collection is too deep.DynaTraceOfMichael KoppThe same is true, but he causesJavaThe main causes of Memory leakage are listed.
<! -- [If! SupportLists] -->1,<! -- [Endif] --> Thread Local variableThread Local Variables
It is easy to appear when the thread pool is used.Heap dumpIt is easy to locate the problem;
2,<! -- [Endif] --> variable static fields and setsMutable 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,<! -- [Endif] --> loops and complex bidirectional referencesCircular 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;
<! -- [If! SupportLists] -->4,<! -- [Endif] -->JNIMemory leakageJNI memory leaks
I'm not using much.
<! -- [If! SupportLists] -->5,<! -- [Endif] --> classEquals/hashcodeIncorrect implementation
Use such a classHashMapProblems may occur easily.
To avoid this problem, perform a test, such as the tool:Http://code.google.com/p/equalsverifier/
<! -- [If! SupportLists] -->6,<! -- [Endif] --> Memory leakage caused by class loaders
Class LoaderThe application server andOSGiContainers are easy to appear.
Maybe the reply is more exciting.1, 2, 6Combined:
Static ThreadLocal myWrapper =
New ThreadLocal (){
NotThreadSafeObject initialValue (){
Return new NotThreadSafeObject ();
}
}
...
MyWrapper. get (). someMethod ()
...
More details at html "> http://www.szegedi.org/articles/memleak.html
How to use:DynaTraceSee here:
Http://blog.dynatrace.com/2011/04/13/application-performance-monitoring-in-production-a-step-by-step-guide/