编程知识 cdmana.com

Soft reference and virtual reference in Java

Strong citation

First of all, I built a class M See when to call finalize Method

public class M {
@Override
protected void finalize() throws Throwable {

    System.out.println("~finalize");

super.finalize();
}
}

public class NormalReference {

public static void main(String[] args) throws IOException {
    M m = new M();

m=null;
System.gc();
System.out.println(m);
System.in.read();
}
}

版权声明
本文为[zzh Z]所创,转载请带上原文链接,感谢

Scroll to Top