Search code examples
javagarbage-collectionspecificationsfinalizefinalization

Definition: Unfinalized versus finalizable object


In order to understand weak references in Java, I have had to consult the Java Language Specification. The following part, from section 12.6, puzzles me:

An unfinalized object has never had its finalizer automatically invoked; a finalized object has had its finalizer automatically invoked. A finalizable object has never had its finalizer automatically invoked, but the Java virtual machine may eventually automatically invoke its finalizer.

So what is the formal difference between an unfinalized and a finalizable object ? From the quote it seems that if unfinalized and finalizable are to be different, then for an unfinalized object it must be the case that it is not true that the JVM may eventually invoke its finalizer. A little confusing or I still have some English semantics to study ;)

Link to the section in the Java spec: Implementing Finalization


Solution

  • The difference between an unfinalized and a finalizable object is that the finalizer on the second one could be automatically invoked at any time in the future, while the finalizer on the unfinalized object can't be automatically invoked, unless the object first becomes finalizable.

    • a unfinalized object will not get its finalizer automatically invoked by the JVM in this state
    • a finalizable object can eventually get its finalizer automatically invoked by the JVM