Tss Translation: common Java memory problems Part 1

Source: Internet
Author: User
Tags dynatrace

 


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/

 

 

 

 

Related Article

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.