@Java VisualVM分析堆转储文件

测试程序

public class HeapOOM {
    private static int i = 0;

    static class OOMObject {
    }

    public static void main(String[] args) {
        List<OOMObject> list = new ArrayList<OOMObject>();
        try {
            while (true) {
                list.add(new OOMObject());
                i++;

            }
        } finally {
            //810325
            System.out.println(i);
        }

    }
}

输出:

[GC (Allocation Failure)  5142K->3031K(19968K), 0.0070246 secs]
[GC (Allocation Failure)  8663K->7062K(19968K), 0.0066110 secs]
[GC (Allocation Failure)  12694K->12708K(19968K), 0.0091115 secs]
[Full GC (Ergonomics)  12708K->10719K(19968K), 0.1400352 secs]
[Full GC (Ergonomics)  16351K->14231K(19968K), 0.1051886 secs]
[Full GC (Ergonomics)  16799K->16622K(19968K), 0.1139390 secs]
[Full GC (Allocation Failure)  16622K->16593K(19968K), 0.1047700 secs]
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid11700.hprof ...
Heap dump file created [28412377 bytes in 0.082 secs]
810325
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3210)
    at java.util.Arrays.copyOf(Arrays.java:3181)
    at java.util.ArrayList.grow(ArrayList.java:261)
    at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
    at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
    at java.util.ArrayList.add(ArrayList.java:458)
    at HeapOOM.main(HeapOOM.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

使用Java VisualVM查看堆转储文件java_pid11700.hprof

可以看到OOMObject这个类有810326个实例,导致内存溢出OOM。

 

转载于:https://www.cnblogs.com/winner-0715/p/7307064.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值