public class HeapOom{
List<Object> list =newArrayList<Object>();
public static void main(String[] args){newHeapOom().test();}/**
* 不断的创建对象导致堆内存溢出
*/
public void test(){while(true){
list.add(newObject());}}}
Connected to the target VM, address: '127.0.0.1:39403', transport: 'socket'
java.lang.OutOfMemoryError: Java heap space
Dumping heap to d:heapoom.hprof ...
Heap dump file created [2315152477 bytes in 8.402 secs]
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:265)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
at java.util.ArrayList.add(ArrayList.java:462)
at com.ljb.springboot.oom.HeapOom.test(HeapOom.java:17)
at com.ljb.springboot.oom.HeapOom.main(HeapOom.java:10)
Disconnected from the target VM, address: '127.0.0.1:39403', transport: 'socket'
Process finished with exit code 1
栈内存溢出
public class StackOom{
public static void main(String[] args){newStackOom().test();}/**
* 无出口的递归调用导致栈溢出
*/
public void test(){test();}}
堆内存溢出public class HeapOom { List<Object> list = new ArrayList<Object>(); public static void main(String[] args) { new HeapOom().test(); } /** * 不断的创建对象导致堆内存溢出 */ ...