Heap overflow :
Copy the code code as follows:
/**
* @author LXA
* Heap overflow
*/
public class Heap
{
public static void main(String[] args)
{
ArrayList list=new ArrayList();
while(true)
{
list.add(new Heap());
}
}
}
Error reported:
java.lang.OutOfMemoryError: Java heap space
Stack overflow :
Copy the code code as follows:
/**
* @author LXA
* stack overflow
*/
public class Stack
{
public static void main(String[] args)
{
new Stack().test();
}
public void test()
{
test();
}
}
Error reported:
java.lang.StackOverflowError