zoukankan      html  css  js  c++  java
  • 内存泄漏

    1:三种泄漏方式https://www.cnblogs.com/liuroy/p/6442888.html
        static Map wMap = new WeakHashMap();
        static Map map = new HashMap();
        public static void init(){
            String ref1= new String("obejct1");
            String ref2 = new String("obejct2");
            String ref3 = new String ("obejct3");
            String ref4 = new String ("obejct4");
            wMap.put(ref1, "chaheObject1");
            wMap.put(ref2, "chaheObject2");
            map.put(ref3, "chaheObject3");
            map.put(ref4, "chaheObject4");
            System.out.println("String引用ref1,ref2,ref3,ref4 消失");
    
        }
        public static void testWeakHashMap(){
    
            System.out.println("WeakHashMap GC之前");
            for (Object o : wMap.entrySet()) {
                System.out.println(o);
            }
            try {
                System.gc();
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("WeakHashMap GC之后");
            for (Object o : wMap.entrySet()) {
                System.out.println(o);
            }
        }
        public static void testHashMap(){
            System.out.println("HashMap GC之前");
            for (Object o : map.entrySet()) {
                System.out.println(o);
            }
            try {
                System.gc();
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("HashMap GC之后");
            for (Object o : map.entrySet()) {
                System.out.println(o);
            }
        }
        public static void main(String[] args) {
            init();
            testWeakHashMap();
            testHashMap();
        }
  • 相关阅读:
    第二阶段冲刺总结01
    第十四周学习进度
    第十三周进度
    意见改进
    BZOJ 2109 航空管制(拓扑排序+贪心)
    BZOJ 2131 圈地计划(最小割+黑白染色)
    BZOJ 2118 墨墨的等式(最短路)
    BZOJ 2157 旅行(树链剖分码农题)
    BZOJ 2141 排队(树状数组套主席树)
    BZOJ 2186 沙拉公主的困惑(预处理逆元+欧拉函数)
  • 原文地址:https://www.cnblogs.com/wth21-1314/p/8806953.html
Copyright © 2011-2022 走看看