modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java

Print this page
rev 6979 : RT-37025: StyleManager failed to remove stylesheet containers that reference children of a parent that is removed from the scene

@@ -550,10 +550,31 @@
         if (stylesheets != null && !stylesheets.isEmpty()) {
             for (String fname : stylesheets) {
                 stylesheetRemoved(parent, fname);
             }
         }
+
+        Iterator<StylesheetContainer> containerIterator = stylesheetContainerMap.values().iterator();
+        while (containerIterator.hasNext()) {
+            StylesheetContainer container = containerIterator.next();
+            container.parentUsers.remove(parent);
+            if (container.parentUsers.list.isEmpty()) {
+
+                containerIterator.remove();
+
+                if (container.selectorPartitioning != null) {
+                    container.selectorPartitioning.reset();
+                }
+
+
+                // clean up image cache by removing images from the cache that
+                // might have come from this stylesheet
+                final String fname = container.fname;
+                cleanUpImageCache(fname);
+            }
+        }
+
         // Do not iterate over children since this method will be called on each from Parent#scenesChanged
     }
 
     /**
      * called from Parent's stylesheets property's onChanged method