有关System.gc()和finalize()的一个问题

flywithwind2007 2006-05-05 11:13:01
我最近在学习张孝祥java就业培训的课程,其中讲到一个程序,代码如下:
public 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!
但是我用eclipse编译运行的结果是:
the program is ending!
the object is going!
the object is going!
the object is going!
请问各位,这是不是编译器不同的问题?如果是,在eclipse中应在什么地方调用System.gc方法才能实现他所给出的答案?而且,实现之后,所给出的程序合理吗?多谢各位!!!


...全文
118 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
网络咖啡 2006-05-05
  • 打赏
  • 举报
回复
这个可以理解,System.gc方法只是请求JVM进行垃圾收集,至于什么时候开始,完全取决于JVM.

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧