changeset 5571:cbcef6b84c73

RT-33869: Controls are leaking through focus owner mechanism Reviewed-by: jgiles
author leifs
date Tue, 29 Oct 2013 15:50:44 -0700
parents d83cbe8507e2
children 6633eea3285d
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Tue Oct 29 15:49:43 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextFieldBehavior.java	Tue Oct 29 15:50:44 2013 -0700
@@ -92,21 +92,22 @@
             }
         };
 
+        final WeakChangeListener<Node> weakFocusOwnerListener =
+                                new WeakChangeListener<Node>(focusOwnerListener);
         sceneListener = new ChangeListener<Scene>() {
-            private WeakChangeListener<Node> weakListener = new WeakChangeListener<Node>(focusOwnerListener);
             @Override public void changed(ObservableValue<? extends Scene> observable, Scene oldValue, Scene newValue) {
                 if (oldValue != null) {
-                    oldValue.focusOwnerProperty().removeListener(weakListener);
+                    oldValue.focusOwnerProperty().removeListener(weakFocusOwnerListener);
                 }
                 if (newValue != null) {
-                    newValue.focusOwnerProperty().addListener(weakListener);
+                    newValue.focusOwnerProperty().addListener(weakFocusOwnerListener);
                 }
             }
         };
         textField.sceneProperty().addListener(new WeakChangeListener<Scene>(sceneListener));
 
         if (textField.getScene() != null) {
-            textField.getScene().focusOwnerProperty().addListener(focusOwnerListener);
+            textField.getScene().focusOwnerProperty().addListener(weakFocusOwnerListener);
         }
 
         // Only add this if we're on an embedded platform that supports 5-button navigation