求问大神:为什么totalmemory在虚拟机运行前后没有变化??

     
        long startM=Runtime.getRuntime().totalMemory();//开始时间的系统内存
        List l=new ArrayList();
        Map m = new HashMap();
        for (int i = 0; i < 100000; i++) {
            Float r = new Float(Math.random()*10);
            l.add(r);
            double area =Math.PI*r*r;
            m.put("r".concat(String.valueOf(r)),new String("半径为"+String.valueOf(r)+"时,面积为"+String.valueOf(area)));
        }
        Iterator entries = m.entrySet().iterator();
        while(entries.hasNext()){
            Map.Entry entry=(Map.Entry)entries.next();
            String key =(String)entry.getKey();//半径
            String value=(String)entry.getValue();//面积
            System.out.println(key+"   "+value);
        }
        long endM=Runtime.getRuntime().totalMemory();
        System.out.println("系统开始时可使用的内存"+startM);
        System.out.println("系统结束时可使用的内存"+endM);
        String memory = "系统运行总共用了".concat(String.valueOf((startM-endM))).concat("秒");
        System.out.println(memory);
        System.gc();
        System.out.println("垃圾回收后的内存"+Runtime.getRuntime().totalMemory());

 

使用的时idea 2020 3.2版本

     
        long startM=Runtime.getRuntime().totalMemory();//开始时间的系统内存
        List l=new ArrayList();
        Map m = new HashMap();
        for (int i = 0; i < 100000; i++) {
            Float r = new Float(Math.random()*10);
            l.add(r);
            double area =Math.PI*r*r;
            m.put("r".concat(String.valueOf(r)),new String("半径为"+String.valueOf(r)+"时,面积为"+String.valueOf(area)));
        }
        Iterator entries = m.entrySet().iterator();
        while(entries.hasNext()){
            Map.Entry entry=(Map.Entry)entries.next();
            String key =(String)entry.getKey();//半径
            String value=(String)entry.getValue();//面积
            System.out.println(key+"   "+value);
        }
        long endM=Runtime.getRuntime().totalMemory();
        System.out.println("系统开始时可使用的内存"+startM);
        System.out.println("系统结束时可使用的内存"+endM);
        String memory = "系统运行总共用了".concat(String.valueOf((startM-endM))).concat("秒");
        System.out.println(memory);
        System.gc();
        System.out.println("垃圾回收后的内存"+Runtime.getRuntime().totalMemory());