• final finally finalize 区别


    public class Demo {
        public static void main(String[] args) {
            
            long start = System.currentTimeMillis();//当前系统时间
            Runtime runtime = Runtime.getRuntime();
            System.out.println("刚开始  最大内存: "+runtime.maxMemory()/1024.0/1024+"M");
            System.out.println("刚开始  总共内存: "+runtime.totalMemory()/1024.0/1024+"M");
            System.out.println("刚开始  剩余内存: "+runtime.freeMemory()/1024.0/1024+"M");
            
        //    runtime.gc();//垃圾回收
            String str = null;
            for(int i=0;i<1000;i++) {
                str+=i;
            }
            System.out.println("循环后  最大内存: "+runtime.maxMemory()/1024.0/1024+"M");
            System.out.println("循环后  总共内存: "+runtime.totalMemory()/1024.0/1024+"M");
            System.out.println("循环后  剩余内存: "+runtime.freeMemory()/1024.0/1024+"M");
            
            System.gc();//也是调的Runtime的gc()
            System.out.println("gc后  最大内存: "+runtime.maxMemory()/1024.0/1024+"M");
            System.out.println("gc后  总共内存: "+runtime.totalMemory()/1024.0/1024+"M");
            System.out.println("gc后  剩余内存: "+runtime.freeMemory()/1024.0/1024+"M");
            
            long end = System.currentTimeMillis();//当前系统时间
            System.out.println("运行用时: "+(end-start)+"毫秒");
            
        }
        /**
         * final 定义不能够被继承的父类,不能够被子类覆写的方法,定义常量
         * finally 是在异常处理中进行异常处理的统一出口
         * finalize 是Object类的一个方法protected void finalize() throws Throwable
         * 当系统调用System.gc()进行回收时,会调用finalize()进行收尾,相当于希构函数
         * */
        @Override
        protected void finalize() throws Throwable {
            super.finalize();
            
        }
    }
  • 相关阅读:
    12.python中的列表
    11.python中的元组
    10.python中的序列
    9.python的布尔类型与流程控制
    8.python中的数字
    7.python字符串-内置方法分析
    Boost--lexical_cast 一个方便安全高效的string转换库
    STL进阶--vector vs deque
    STL进阶--删除元素
    STL进阶--相等 vs 等价 (Equality vs Equivalence)
  • 原文地址:https://www.cnblogs.com/wwzyy/p/5534963.html
Copyright © 2020-2023  润新知