Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8117738

Removed from scene nodes are not being garbage collected

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      Linux x86-64, JDK 1.8.0-ea-b114

      Description

      In JDK8 b114 replaced or removed from scene nodes are not being garbage collected. In following sample after each click on Replace button one more instance of TextField object can be found in VisualVM dumps. In b113 and early builds, however, only 2 instances of TextField listed in dumps after garbage collection.

      import javafx.application.Application;
      import javafx.event.Event;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;

      public class Test extends Application {
      public static void main(String[] args) {
      Application.launch(args);
      }

      private GridPane root;
      private TextField testField;
      private TextField text;

      public Test() {
      }

      private void onReplace(Event event) {
      root.getChildren().remove(testField);
      root.add(testField = new TextField(), 0, 1);
      final Runtime r = Runtime.getRuntime();
      r.gc();
      r.runFinalization();
      final long total = r.totalMemory();
      text.setText(String.format("%d of %d bytes used",
      total - r.freeMemory(), total));
      }

      @Override
      public void start(Stage primaryStage) throws Exception {
      root = new GridPane();
      root.setHgap(10);
      root.setVgap(10);
      root.setPadding(new Insets(10, 10, 10, 10));
      final Button replace = new Button("Replace");
      replace.setOnAction(this::onReplace);
      text = new TextField();
      text.setMinWidth(250d);
      root.addRow(0, replace, text);
      onReplace(null);
      primaryStage.setScene(new Scene(root));
      primaryStage.setTitle("Test");
      primaryStage.show();
      }
      }

        Attachments

          Activity

            People

            • Assignee:
              msladecek Martin Sládeček
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: