在OutOfMemory时生成java转储
发布时间:2020-12-15 02:54:43 所属栏目:Java 来源:网络整理
导读:我有一个程序,最终应该生成OutOfMemory. 程序代码是: 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
我有一个程序,最终应该生成OutOfMemory.
程序代码是: 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" 程序因OutOfMemory失败,但未生成转储文件.你知道为什么吗? Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at VeryLargeObject.<init>(VeryLargeObject.java:14) at VeryLargeObject.main(VeryLargeObject.java:32) 解决方法
对于启动器删除XX选项和任何选项BEFORE VeryLargeObject,否则您将参数传递给java程序而不是JVM
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |