changeset 1682:35ef14b60ba4

RT-32968: Memory leaked when using custom CSS file for JavaFX Reviewed-By: dgrieve, anashaty
author dmarkov
date Thu, 19 Sep 2013 11:11:24 +0400
parents 1d7c9e2e7ba5
children 8ec7f7f24b63
files javafx-ui-common/src/com/sun/javafx/css/StyleManager.java javafx-ui-common/src/javafx/stage/Window.java
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Tue Sep 03 20:38:46 2013 +0400
+++ b/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Thu Sep 19 11:11:24 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -808,6 +808,21 @@
     }
 
     /**
+     * Removes the objects related to the scene from the cache.
+     * Called from Window when the scene is closed.
+     *
+     * @param scene the scene
+     */
+    public void forget(Scene scene) {
+        if (containerMap != null) {
+            final StylesheetContainer container = remove(containerMap, scene);
+            if (container != null) {
+                container.destroy();
+            }
+        }
+    }
+
+    /**
      * Creates stylesheets and associates them with the given scene.
      *
      * Called from Scene.stylesheets on replace. Attempts to reuse existing
@@ -850,9 +865,6 @@
             }
         }
 
-        // if there are no stylesheets, then they were probably all removed.
-        if (scene.getStylesheets().size() == 0) return;
-
         // RT-20643
         CssError.setCurrentScene(scene);
         
--- a/javafx-ui-common/src/javafx/stage/Window.java	Tue Sep 03 20:38:46 2013 +0400
+++ b/javafx-ui-common/src/javafx/stage/Window.java	Thu Sep 19 11:11:24 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -396,6 +396,7 @@
                 // will also trigger scene's peer disposal.
                 if (oldScene != null) {
                     oldScene.impl_setWindow(null);
+                    StyleManager.getInstance().forget(oldScene);
                 }
                 if (newScene != null) {
                     final Window oldWindow = newScene.getWindow();
@@ -747,6 +748,7 @@
                     if (getScene() != null) {
                         impl_peer.setScene(null);
                         getScene().impl_disposePeer();
+                        StyleManager.getInstance().forget(getScene());
                     }
 
                     // Remove toolkit pulse listener