Hi,

I had a look quick look around in the bugs lists for something to try
fixing. I happened on this issue.

I am aware that the other primitive binding classes should have similar
treatment.
But I wanted to get approval/hints before continuing.

The change adds a new inner class that allows the wrapped binding to be
unbound when the parent is.

There is no test (hard to test presence/absence of a leak).

Thanks,
Jesper
diff --git 
a/modules/base/src/main/java/javafx/beans/property/BooleanPropertyBase.java 
b/modules/base/src/main/java/javafx/beans/property/BooleanPropertyBase.java
--- a/modules/base/src/main/java/javafx/beans/property/BooleanPropertyBase.java
+++ b/modules/base/src/main/java/javafx/beans/property/BooleanPropertyBase.java
@@ -164,17 +164,7 @@
         }
 
         final ObservableBooleanValue newObservable = (rawObservable instanceof 
ObservableBooleanValue) ? (ObservableBooleanValue) rawObservable
-                : new BooleanBinding() {
-                    {
-                        super.bind(rawObservable);
-                    }
-
-                    @Override
-                    protected boolean computeValue() {
-                        final Boolean value = rawObservable.getValue();
-                        return (value == null)? false : value;
-                    }
-                };
+                       : new WrappedBooleanBinding(rawObservable);
 
         if (!newObservable.equals(observable)) {
             unbind();
@@ -195,6 +185,9 @@
         if (observable != null) {
             value = observable.get();
             observable.removeListener(listener);
+            if (observable instanceof WrappedBooleanBinding) {
+               ((WrappedBooleanBinding)observable).unbind();
+            }
             observable = null;
         }
     }
@@ -228,6 +221,25 @@
         return result.toString();
     }
 
+    private static class WrappedBooleanBinding extends BooleanBinding {
+       final ObservableValue<? extends Boolean> rawObservable;
+       WrappedBooleanBinding(final ObservableValue<? extends Boolean> 
rawObservable) {
+            super.bind(rawObservable);
+            
+            this.rawObservable = rawObservable;
+        }
+
+        @Override
+        protected boolean computeValue() {
+            final Boolean value = rawObservable.getValue();
+            return (value == null)? false : value;
+        }
+        
+        protected void unbind() {
+            super.unbind(rawObservable);
+        }
+    };
+    
     private static class Listener implements InvalidationListener {
 
         private final WeakReference<BooleanPropertyBase> wref;

Reply via email to