zoukankan      html  css  js  c++  java
  • 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);
        }
    }

  • 相关阅读:
    maven项目诡异的问题
    13) Developing Java Plugins
    15) maven dependency scope
    Bootstrap学习记录
    电力
    MongoDB学习记录
    Java基础知识
    旅游
    人生感悟
    【转】25岁到55岁:如何规划人生最重要的三个十年
  • 原文地址:https://www.cnblogs.com/xiluhua/p/10800132.html
Copyright © 2011-2022 走看看