JDK-4701292 : non-resurrectible finalization mechanism required
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2002-06-12
  • Updated: 2015-12-04
  • Resolved: 2015-12-04
Related Reports
Duplicate :  
Description
the current finalization mechanism can obviously resurrect
the object & hence objects with a finalize() method can
cause serious gc performance problems (see bugs like
4525290 and 4239841 - which probably aren't bugs but do
demonstrate the issue)

one solution is to develop the application such that classes
do not have finalize() methods but to instead use weak or
phantom references so that the original object (referent) can
undergo gc immediately & the tidyup can be done sometime later.

whilst this workaround is not difficult for an application
developer to implement, it is still a lot more work that using
a finalize() method. also, it requires the application developer
to create the required infrastructure so is not something that
an isv providing utility class libraries could use.

one solution (requiring no lang change) would be to add a
system reference queue (sort of thing;) to which one could add an
object (which is used like a weak/phantom referent) and an associated
FinalizationObject (sort of thing) whose doTidyup() method could
be called by the (system provided) thread monitoring this ref queue.

maybe some sort of (java language supported?) inner
finalization class would be more elegant.

Comments
The topic of this issue is covered by the java.lang.ref.Cleaner and can be closed as a duplicate.
04-12-2015