Heap overflow:
/** * @author LXA * 堆溢出 */ public class Heap { public static void main(String[] args) { ArrayList list=new ArrayList(); while(true) { list.add(new Heap()); } } }
Error report:
java.lang.OutOfMemoryError: Java heap space
Stack overflow:
/** * @author LXA * 栈溢出 */ public class Stack { public static void main(String[] args) { new Stack().test(); } public void test() { test(); } }
Error report:
java.lang.StackOverflowError
For more java memory overflow examples (heap overflow, stack overflow) related articles, please pay attention to the PHP Chinese website!