Java memory overflow example of of heap overflow stack overflow
- 2020-04-01 03:20:21
- OfStack
Stack overflow :
/**
* @author LXA
* Stack overflow
*/
public class Heap
{
public static void main(String[] args)
{
ArrayList list=new ArrayList();
while(true)
{
list.add(new Heap());
}
}
}
Error:
Java. Lang. OutOfMemoryError: Java heap space
Stack overflow :
/**
* @author LXA
* Stack overflow
*/
public class Stack
{
public static void main(String[] args)
{
new Stack().test();
}
public void test()
{
test();
}
}
Error:
Java. Lang. StackOverflowError