TSS Translation: common Java memory problems Part 1

Source: Internet
Author: User

 

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/

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.