--- old/modules/graphics/src/main/java/javafx/scene/Parent.java 2015-09-27 21:40:30.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/Parent.java 2015-09-27 21:40:30.000000000 -0700 @@ -497,7 +497,10 @@ old.setParent(null); old.setScenes(null, null); } - if (!removedChildrenOptimizationDisabled) { + // Do not add parent with null scene to the removed list. + // It will not be processed in the list and its memory + // will not be freed. + if (scene != null && !removedChildrenOptimizationDisabled) { removed.add(old); } } @@ -646,6 +649,13 @@ } } + // This method is to do cleanup on parent when it is removed from a scene + private void nullSceneCleanup() { + if (removed != null) { + removed.clear(); + } + } + @Override void scenesChanged(final Scene newScene, final SubScene newSubScene, final Scene oldScene, final SubScene oldSubScene) { @@ -653,6 +663,7 @@ if (oldScene != null && newScene == null) { // RT-34863 - clean up CSS cache when Parent is removed from scene-graph StyleManager.getInstance().forget(this); + nullSceneCleanup(); } for (int i=0; i