有关System.gc()和finalize()的一个问题
我最近在学习张孝祥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方法才能实现他所给出的答案?而且,实现之后,所给出的程序合理吗?多谢各位!!!