publicstaticvoidmain(String[] args){ ArrayList<OOMObject> list = new ArrayList<>(); int a = 1; while (true) { list.add(new OOMObject(String.valueOf(a ++))); } } }
java.lang.OutOfMemoryError: Java heap space Dumping heap to d:\jvmtest ... Unable to create d:\jvmtest: File exists 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 jvm.oom.TestOOM.main(TestOOM.java:18)