RFR 9: 8165641 : Deprecate Object.finalize
stuart.marks at oracle.com
Tue Mar 14 17:37:25 UTC 2017
Tagir Valeev asked on Twitter whether System.runFinalization() and
Runtime.runFinalization() should also be deprecated. The obvious answer is "yes"
since we're deprecating finalization, but maybe it's not so obvious.
One view is that we're not deprecating the entire finalization mechanism, we're
simply deprecating Object.finalize() and its overrides. The point of doing this
is to encourage code to migrate away from these methods. Code that calls
runFinalization() can't rely on it having many semantics, so such calls are
harmless. (Well, mostly harmless.) Encouraging migration away from
runFinalization() thus isn't necessary.
Another point is that "finalization" in a generic sense can be applied to
reference processing, not just calls to the finalize() method. Offhand I'm not
sure what runFinalization() does today, but perhaps in the future it could be
modified to have stronger semantics regarding reference processing -- which is
one of the big unresolved issues in this area.
What do you think?
On 3/10/17 1:40 PM, Roger Riggs wrote:
> Finalizers are inherently problematic and their use can lead to performance issues,
> deadlocks, hangs, and other problematic behavior.
> 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.
> The behavior of finalization nor any uses of finalize are not modified by this
> Most of the changes are to suppress compilation warnings within the JDK.
> Please review and comment.
> Thanks, Roger
More information about the core-libs-dev