标题: finalize与system.gc() [打印本页] 作者: 仲伟 时间: 2013-5-13 16:50 标题: finalize与system.gc() 原帖的地址:http://bbs.csdn.net/topics/80089815
class person{
public void finalize(){
System.out.println("the object is going!");
}
public static void main(String[] args){
new person();
new person();
new person();
System.gc();
System.out.println("the program is ending!");
}
}
运行结果如下
the object is going!
the object is going!
the object is going!
the program is ending!
问题如下
1:我认为运行结果应该是
the object is going!
the program is ending!
为什么强制执行回收会执行三遍?
2:谁能告诉我System.gc的运行原理?
3:finalize()怎么释放这3个匿名存储空间?
4:如果System.gc不强制运行,这3个匿名垃圾非要等到程序空闲才会被自动回收何不把这个方法直接改成手动的?作者: 仲伟 时间: 2013-5-13 16:51
1:我认为运行结果应该是
the object is going!
the program is ending!
为什么强制执行回收会执行三遍?