java 内存溢出总结

/**
 * jvm 参数: -Xms5m -Xmx5m -Xmn2m -XX:NewSize=1m
 * @author admin
 *
 */
public class HeapOutOfMemoryError {
    
    //
    @SuppressWarnings("unused")
    private String[] strings = new String[100000];
    
    public static void main(String[] args) {
        Map<Object, HeapOutOfMemoryError> map = new HashMap<Object, HeapOutOfMemoryError>();
        int i = 0;
        
        do {
            map.put(String.valueOf(i), new HeapOutOfMemoryError());
            i++;
        } while (i<100000);
    }
}

 

方法区(永久代)

public class PermOutOfMemoryError {

    // 方法区
    @SuppressWarnings("unused")
    private static String[] strings = new String[100000];
    
    public static void main(String[] args) {
        Map<Object, PermOutOfMemoryError> map = new HashMap<Object, PermOutOfMemoryError>();
        int i = 0;
        
        do {
            map.put(String.valueOf(i), new PermOutOfMemoryError());
            i++;
        } while (i<100000);
    }
}

 

public class StackOverFlowError {

    public static void main(String[] args) {
        int i = 0;
        go(i);
    }

    @SuppressWarnings("unused")
    private static void go(int i) {
        System.out.println(i);
        String[] strings = new String[100000];
        i++;
        go(i);
    }
}

猜你喜欢

转载自www.cnblogs.com/xiluhua/p/10800132.html
今日推荐