In the example code below, when an instance of Example
becomes unreachable, the object that os
refers to will be finalizer-reachable.
public class Example {
private OutputStream os;
public Example(OutputStream os) {
this.os = 0s;
}
protected void finalize() {
try {
os.close();
} catch (IOException ex) {
// ignore it
}
}
}
However, if the Example
instance was no longer eligible for finalization (e.g. because it had been finalized previously and then "resurrected" during finalization), then os
would not be finalizer-reachable.
The "finalizer-reachable" state is about specifying that objects that may be referred to during finalization don't get deleted prematurely. The specification does not state how this should be ensured. I imagine that it would not be possible for Java code (or even native code) to determine whether a specific object was is this state.