标签:
一、内存溢出时生成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指定的路径必须存在
标签:
原文地址:http://www.cnblogs.com/zno2/p/4607087.html