MAT analysis of the dump file

public class OOM {
    private static List<Byte[]> list = new ArrayList<Byte[]>();
    public static void main(String[] args) {
        Zip zip = new Zip();
        zip.test(list);
    }
}
public class Zip {
    private List<Byte[]> a = null;

    public List<Byte[]> getA() {
        return a;
    }

    public void setA(List<Byte[]> a) {
        this.a = a;
    }
    public void test(List<Byte[]> list){
        Zip n = new Zip();
        n.setA(list);
        R r = new R();
        r.test1(n);
    }
}
public class R {
    public void test1(Zip z){
        while(true){
            Byte[] b = new Byte[100000];
            z.getA().add(b);
        }
    }
}

I deliberately created a piece of code that will overflow.

By the leak suspects can be seen in FIG. Analysis of the gc root. Comparison code and the ba.

 

 There are other ways to analyze, click the dominator tree can get to the thread to hold large objects, then you can also perform the analysis gcroot thereon, as shown below.

 

 

 

 

Last words,

The actual situation is not so clear. You may need to have every point on the gc root path a little to find in the end where the problem occurred.

Guess you like

Origin www.cnblogs.com/coolgame/p/12157954.html
Recommended