On Tue, 18 Feb 2020 20:09:59 GMT, Kevin Rushforth <k...@openjdk.org> wrote:
>>> the referent to the created property object has been garbage collected >>> before the `finalize` method is called >> >> I'm confused. What is that referent exactly and why is it guaranteed to have >> been GC'd before finalization? > >> > the referent to the created property object has been garbage collected >> > before the `finalize` method is called >> >> I'm confused. What is that referent exactly and why is it guaranteed to have >> been GC'd before finalization? > > I meant the referent of the `WeakReference` to the constructed `Property` > object on which the `finalize` method is being called. > > The `asObject` and `xxxxxProperty` methods create a bidirectional binding, > which uses weak references to both the original `Property` object and the > newly constructed `Property` object. The `finalize` method is on the > newly-constructed `Property`. By the time that finalize method is called, the > JVM guarantees that no other reference to that `Property` object exists. > From the API docs of `Object::finalize`: > > _The general contract of finalize is that it is invoked if and when the Java™ > virtual machine has determined that there is no longer any means by which > this object can be accessed by any thread that has not yet died, except as a > result of an action taken by the finalization of some other object or class > which is ready to be finalized._ The logic seems correct. The weak reference to the newly created property in the bidirectional binding must be cleared before `finalize` is called. The unbinding attempt only interferes with GC. I still have to go over the tests. I note that with the removal of the finalize methods, the method `BidirectionalBinding#unbindNumber` is left unused and can be removed. Also, the changed property classes and `BidirectionalBinding` can use some cleanup that I can do after this is fixed, so I can remove that method at that time if you don't want to do it here. ------------- PR: https://git.openjdk.java.net/jfx/pull/113