class Garbage
{
int index;
static int count;
Garbage()
{
count++;
System.out.println("Object" + count + "construct");
setID(count);
}

void setID(int id)
{
index = id;
}

protected void finallze()
{
System.out.println("object" + index + "is reclaimed");
}

public static void main(String args[])
{
new Garbage();
new Garbage();
new Garbage();
new Garbage();
System.gc();
}
}

解决方案 »

  1.   

    finallze()写错了----->finalize()
      

  2.   

    其实Java中没有任何机制保证程序能强制执行垃圾回收,gc()不行,其他任何方法都不行。
    调用gc()只能告诉jvm说,我想现在运行垃圾回收,而jvm究竟什么时间进行,那是jvm自己的事,程序无权干涉。
      

  3.   

    System.gc();的作用如下:我:Hi,楼主结贴了!你:但是你结不结贴是你的事情,我没有办法控制你马上结贴。