changeset 6611:976774eccaa8

[TEST ONLY] Fix UI control memory leaks that were preventing all tests from executing (on certain machines).
author jgiles
date Thu, 03 Apr 2014 16:22:55 +1300
parents c28c32569f30
children ce02f2287ba3
files modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/StageLoader.java
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/StageLoader.java	Thu Apr 03 15:28:15 2014 -0400
+++ b/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/StageLoader.java	Thu Apr 03 16:22:55 2014 +1300
@@ -52,16 +52,30 @@
         stage.setScene(scene);
         stage.show();
     }
-    
+
+    // bad I know, but this is better than having unit tests running out of memory
+    // and stalling. If this isn't done we leave all stages in memory as they
+    // are collected in a static list (Stage.stages). The alternative is to
+    // expect all users of StageLoader (i.e. ui controls unit tests) to always
+    // properly clean up after themselves.
+    @Override protected void finalize() throws Throwable {
+        dispose();
+        super.finalize();
+    }
+
     public Stage getStage() {
         return stage;
     }
     
     public void dispose() {
-        stage.hide();
-        group.getChildren().clear();
-        group = null;
-        scene = null;
-        stage = null;
+        if (group != null) {
+            group.getChildren().clear();
+            group = null;
+        }
+        if (stage != null) {
+            stage.hide();
+            scene = null;
+            stage = null;
+        }
     }
 }