施进超

导航

OOM和SOF代码

OutOfMemoryError大数组,例如图片加载。

public class MockOutOfMemoryError
{
    public static void main(String[] args)
    {
        List<int[]> list = new ArrayList<int[]>();
        for (;;)
        {
            int[] temp = new int[1000000];
            list.add(temp);
        }
    }
}

StackOverFlowError,递归层数太深

public class MockStackOverFlow
{
    public static void method()
    {
        for(;;)
        {
            method();
        }
    }

    public static void main(String[] args)
    {
        method();
    }
}

posted on 2019-07-08 23:49  jinzhaoshi  阅读(209)  评论(0编辑  收藏  举报