Home > Java > javaTutorial > body text

Java memory overflow examples (heap overflow, stack overflow)

高洛峰
Release: 2017-01-24 14:58:20
Original
1434 people have browsed it

Heap overflow:

/**
* @author LXA
* 堆溢出
*/
public class Heap
{
    public static void main(String[] args)
    {
        ArrayList list=new ArrayList();
        while(true)
        {
            list.add(new Heap());
        }
    }
}
Copy after login

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();
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template