I am a newbie on Java. I need your help on a puzzle on java's
finalizer.There is an item on finalizer, "Avoid finalizers", in Joshua
Bloch's famous book "Effective Java". He gave an idiom called "Finalizer
Guardian" to make sure the superclass's finalizer to be performed whenever
derivedclass's finalizer is called. here is the code:
// Finalizer Guardian idiom
public class Foo {
// Sole purpose of this object is to finalize outer Foo object
private final Object finalizerGuardian = new Object() {
protected void finalize() throws Throwable {
// Finalize outer Foo object
...
}
};
... // Remainder omitted
}
My quesition is how this idiom can assure the Foo's annonymous inner
instance's finalizer will be performed when the Foo's derived instance's
finalizer is called by the GC. When GC calls a object's finalizer, Will it
definetely call the member's finalizer?