我有一个应该最终生成OutOfMemory
的程序。 程序代码是:当OutOfMemory生成Java转储
public class VeryLargeObject implements Serializable {
public static final int SIZE = 1 << 12;
public String tag;
public int[][] bigOne = new int[SIZE][SIZE];
{
// Initialize bigOne
for(int i = 0; i < SIZE ; ++i) {
for(int j = 0; j < SIZE; ++j) {
bigOne[i][j] = (int) (Math.random() * 100);
}
}
}
public VeryLargeObject(String tag) {
this.tag = tag;
}
public static void main(String args[]) {
VeryLargeObject[] vla = new VeryLargeObject[1 << 12];
for(int i = 0; i < Integer.MAX_VALUE; ++i) {
vla[i] = new VeryLargeObject("aa");
}
}
}
我用下面的参数运行程序:
java VeryLargeObject -Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="D:\workspace"
该计划失败,内存溢出,但不会生成转储文件。你有什么想法,为什么?
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at VeryLargeObject.<init>(VeryLargeObject.java:14)
at VeryLargeObject.main(VeryLargeObject.java:32)
你的意思是说堆文件没有生成?并且不应该是-XX:-HeapDumpOnOutOfMemoryError而不是-XX:+ HeapDumpOnOutOfMemoryError(注意+号) – CoolBeans 2011-02-08 16:29:40
>程序失败,出现OutOfMemory,但现在在生成文件时转储。 - 这是一个错字吗? - 你的意思是**现在**还是**没有**? – Ralph 2011-02-08 16:43:13