下面是我的程序,但是finalize()并没有被自动调用啊?这是咋回事?
public class ConstructorExercise{
    public ConstructorExercise(){
        System.out.println("without param# I love java");    }
    public ConstructorExercise(String s){
        System.out.println("with param# " + s);
    }
    public void finalize(){
        System.out.println("aaaaaa..........");
    }
    public static void main(String[] arg){
        ConstructorExercise c1 = new ConstructorExercise();
        ConstructorExercise c2 = new ConstructorExercise("abcd");
        System.gc();
    
    }
}

解决方案 »

  1.   

    new test();
            new test("abcd");
            System.gc();
      

  2.   

    finalize()是在垃圾回收之前被自动调用 ,当对象不在有引用指向它的时候,它就变成了垃圾,但是不一定马上就被回收,即使是用了system.gc() ,jvm会在一个不确定的时间回收。
      

  3.   

    finalize 只是告诉VM 这个需要回收。但具体的回收时机还是不可控制的。------ 以下是签名 ------
    SoftDN.com, 提供免费的项目管理平台:SVN仓库、需求管理、BUG跟踪、任务管理、在线论坛、网站空间、项目存储及完整的备份等。欢迎网友光临建立项目,开创自己的梦想。
    地址:http://www.softdn.com   http://www.softdn.cn
      

  4.   

    wanguanghai(心灵鸡汤)  
    _____
    up ..