Oracle recommends axing Java object finalizer

Java’s Object.finalize capability is on the chopping block, deemed more trouble than it’s worth. But expect it to stick around for a while.

Deprecation has been proposed for Java Development Kit (JDK) 9, Oracle said. Oracle recommends that the capability no longer be used and a warning will be issued. Initially, Object.finalize won’t be deprecated for removal, so at the earliest, it could be dropped in Java SE 11. With JDK 9 due this July and JDK 10 presumably in the mix, the capability could still be available for several years.

A part of Java since the nearly 22-year-old language was founded, the Object.finalize method provides object cleanup operations before an object is discarded. However, the timing is unpredictable, with no guarantee the finalizer will be called, according to Oracle.

The use of a finalizer is in fact “problematic,” said Oracle’s Roger Riggs in a recent post to an openjdk mailing list proposing deprecation. A finalizer can lead to performance issues, hangs, and deadlocks. “The problems have been accumulating for many years and the first step to deprecate Object.finalize and the overrides in the JDK to communicate the issues, recommend alternatives, and motivate changes where finalization is currently used.”


One Comment

Add a Comment

Your email address will not be published. Required fields are marked *