Memory leak analysis trilogy using Eclipse Memory Analyzer

Source: Internet
Author: User

Reprint: http://blog.csdn.net/xb151652000/article/details/8056792

Source Address: http://seanhe.iteye.com/blog/898277


First, the preparatory work
Analysis of larger dump files (according to my own experience 2G above the dump file will need to use the method described below, otherwise the mat will appear oom) need to adjust the virtual machine parameters
Find a 64-bit system in Memoryanalyzer.ini setup-xmx2g
If the 32-bit XP can be attempted using the following method:

  • Installing the JDK for JRockit 6.0
  • Mat uses JRockit's JDK to launch Java code
      1. -vm
      2. D:/program files/java/jrockit-r28. 0.0-jre1. 6.0_17/bin/jrockit/jvm.dll
      3. -vmargs
      4. -xmx1700m


    Ii. start the Oom analysis using mat
    The first step, Start mat, select File->open Heap dump to select your dump file. Now wait, Mat parsing the dump file takes some time, while parsing will write some parse result files on the hard disk so that the next time you open it will be much faster. Sometimes the mat in the parsing process may occur error, this time you can delete those temporary files to retry the first step, if your RP is good enough, retry may be resolved successfully.

    Step TwoTo view the memory leak analysis report. The prompt will appear when the mat parsing is complete:

    Because we're looking for a memory leak, keeping the default option directly points to "Finish".
    Mat is very intuitive to show the suspicious point of memory leak, similar to the following report can directly see a thread consuming a lot of memory

    Detailed analysis information for the problem:


    Step three, start looking for the code point that caused the memory leak. At this point, you often need to open the object dependency tree view, click the button.

    You will see the following view

    A large area on the left side of this view can see the object's dependencies, and selecting an object will allow you to see some of the properties of the object in the small left window. If the value of the property is some memory address you can also click on the toolbar's Search button to search for specific object information. Mat is just the function of the tool that helps you with the analysis, and there are no fixed methods and guidelines for OOM problem analysis. Only use your keen insight, combine the source code, analyze the objects in memory to find bugs in the code.

    Tips for use:
    about shallow size, retained size(Excerpt from http://www.360doc.com/content/11/0830/16/4520139_144514377.shtml)
    Shallow size is the amount of memory that the object itself occupies, and does not contain references to other objects, that is, the sum of the object headers plus member variables (not the values of member variables). On a 32-bit system, the object header occupies 8 bytes, and int occupies 4 bytes, regardless of whether the member variable (object or array) refers to another object (instance) or is assigned null, it always consumes 4 bytes. Therefore, for a string object instance, it has three int members (3*4=12 bytes), one char[] member (1*4=4 bytes), and one object header (8 bytes), with a total of 3*4 +1*4+8=24 bytes. According to this principle, for string a= "Rosen Jiang", the shallow size of instance A is also 24 bytes

    Retained size is the object's own shallow size, plus the sum of the shallow size from which the object can be accessed directly or indirectly to the object. In other words, the retained size is the sum of the memory that the object can be recycled to after it has been GC. For a better understanding of retained size, consider an example.

    The objects in memory are treated as nodes in, and objects and objects are referenced to each other. Here's a special node GC Roots, Positive solution! This is the beginning of reference chain.

    Starting with obj1, the middle blue node represents only objects that can be accessed directly or indirectly through OBJ1. Because it can be accessed through GC roots, the OBJ3 on the left is not a blue node, whereas on the right the picture is blue because it is already contained within the retained collection.
    So for the left, the retained size of the obj1 is the sum of the obj4 size of obj1, obj2, Shallow, and the retained size of Obj1, Obj2, Obj3, Obj4 is the sum of shallow size for the right figure. The obj2 retained size can be computed in the same way.

    How to view the memory space occupied by an object
    1. Open a new window as follows

    2. Enter the class name (enter the full name of the class)


Memory leak analysis trilogy using Eclipse Memory Analyzer

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.