I believe such a program ...
class Test { public static void main(String[] args) { new Test(); System.out.println("done"); } protected void finalize() { System.out.println("this object is known to never be referenced."); } }
... perhaps print "this object is known to never be referenced." to "done" . (Correct me if I am wrong!)
In addition, the / JVM compiler can easily detect "unread locales". In the program below, for example, Eclipse notes that "The local variable t is never read."
However, it would be illegal for the JVM to output "this object is known to never be referenced." to "done" given the version (.class) of the program below?
class Test { public static void main(String[] args) { Test t = new Test(); System.out.println("done"); } protected void finalize() { System.out.println("this object is known to never be referenced."); } }
Most garbage collection documentation talks about reachability. Given that t never readable, the object is obviously not "accessible", or?
Links to JLS are welcome.
java garbage-collection
aioobe
source share