一、内存溢出时生成hprof文件
运行参数:
-Xms40m -Xmx40m -Xmn20m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=E:\Java\dump
package cn.zno.outofmomery; import java.util.ArrayList; import java.util.List; public class Main { void h() { List<byte[]> list = new ArrayList<byte[]>(); while (true) { list.add(new byte[1024 * 1024]); } } public static void main(String[] args) { new Main().h(); } }
Console:
java.lang.OutOfMemoryError: Java heap space Dumping heap to E:\Java\dump\java_pid5032.hprof ... Heap dump file created [40841151 bytes in 0.271 secs] Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at cn.zno.outofmomery.Main.h(Main.java:11) at cn.zno.outofmomery.Main.main(Main.java:16)
二、打开文件
获取帮助信息:
注:-XX:HeapDumpPath指定的路径必须存在
时间: 2024-11-29 02:23:32