JDK-8196586 : Remove use of deprecated finalize methods from javafx property objects
  • Type: Bug
  • Component: javafx
  • Sub-Component: base
  • Affected Version: 9,10,openjfx11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-02-01
  • Updated: 2021-05-06
  • Resolved: 2020-02-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx15Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Description
The implementation of the asObject and xxxxxProperty methods in the following classes uses the deprecated Object::finalize method to clean up the property bindings that are created, to avoid a memory leak:

javafx.beans.property.BooleanProperty
javafx.beans.property.DoubleProperty
javafx.beans.property.FloatProperty
javafx.beans.property.IntegerProperty
javafx.beans.property.LongProperty

We should instead use an alternative disposal mechanism, such as a weak or phantom reference-based Disposer used in other places in JavaFX.
Comments
Changeset: 9cd6f791 Author: Kevin Rushforth <kcr@openjdk.org> Date: 2020-02-27 12:14:17 +0000 URL: https://git.openjdk.java.net/jfx/commit/9cd6f791
27-02-2020

Evaluation: The {Boolean,Double,Float,Int,Long}Property classes each have a pair of methods -- asObject and xxxxxProperty -- that create a Property<Xxxxx> object from a primitive XxxxxProperty object and vice versa. Each of the methods bidirectionally binds the original property object to the created property object. All of the bidirectional bindings in question use WeakReferences to refer to the pair of objects being bound to each other, so that they won't cause a memory leak. The finalize methods were added in an attempt to cleanup the bidirectional bindings when the created object goes away. I say attempt, because it is entirely ineffective in doing so. The logic that removes the binding creates a new one from the same pair of objects, but fails to match the original binding because the referent to the created property object has been garbage collected before the finalize method is called; the WeakReference in the binding is cleared and no longer matches. Fortunately, the only impact of this ineffective logic is that it can delay the removal of the binding (which is a small object that just contains the two weak references) from the original property object until it (the original property) is either garbage collected or modified (the binding logic already looks for a referent that has been GCed and removes the binding). Given that the finalize methods don't do anything useful today, and that there is no memory leak in the first place, the proposed fix is to just remove the finalize methods entirely with no replacement needed. There will be no changes in behavior as a result of this. Existing tests of the methods in question are sufficient to ensure no functional regressions, although there is no existing test for leaks, so I will create new tests to verify that there is no leak. Since there is no existing leak, those tests will pass both with and without this fix.
13-02-2020