标签:his pre str [] 退出 static ring name 回收
System.gc()和垃圾回收机制前的收尾方法:finalize(收尾机制)
程序退出时,为每个对象调用一次finalize方法,垃圾回收前的收尾方法
System.gc() 垃圾回收方法
class Person{ private int age; private String name; public Person(int age, String name) { this.age = age; this.name = name; } public String toString() { return "姓名:"+this.name+",年龄:"+this.age; } @Override public void finalize() throws Throwable { // TODO 自动生成的方法存根 //super.finalize(); System.out.println("我完蛋了,我被回收了。。。("+this+")"); } } public class SystemDemo2 { public static void main(String args[]) { Person pr = new Person(110,"张三"); //取消引用 pr = null; //强制进行垃圾回收 System.gc(); } }
java: system.gc()和垃圾回收机制finalize
标签:his pre str [] 退出 static ring name 回收
原文地址:http://www.cnblogs.com/achengmu/p/6260531.html