Skip to main content
 首页 » 编程设计

Java Finalize 方法不调用

2024年06月03日41webabcd

<分区>

这是一段代码。 finalize() 方法应该在 System.gc() 命令之后调用,但事实并非如此。 有什么建议吗?

class test123{ 
    test123(){ 
        System.out.println("Inside the constructor"); 
 
    } 
} 
public class finalizemerthd { 
 
    public static void main(String args[]) { 
        test123 obj1 = new test123(); 
        obj1 = null; 
        System.gc(); 
 
    } 
 
    protected void finalize() throws Throwable 
    { 
        System.out.println("Garbage collector called"); 
        System.out.println("Object garbage collected : " + this); 
    } 
}