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

TabPane does not release cloased tabs and their content

    XMLWordPrintable

    Details

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

      Description

      This problem affects the internal Browser app. If you open several tabs with WebView and close them, you'll see that garbage collector could not release WebView instances. It leads to OutOfMemoryException.

      Try the following automatic test with the following JVM args: -agentlib:hprof=heap=dump,format=b; and jhat shows strong references to TextField instances. Note that the problem is not reproducible if this.pane is not rendered.

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

          private TabPane pane;

          public void start(Stage stage) {
              Tab[] tabs = new Tab[40];
              for (int i = 0; i < tabs.length; i++) {
                  String content = Integer.toString(i);
                  tabs[i] = new Tab(content);
                  tabs[i].setContent(new TextField(content));
              }
              this.pane = new TabPane();
              this.pane.getTabs().addAll(tabs);

              stage.setScene(new Scene(this.pane));
              stage.setVisible(true);

              run();
          }

          public void run() {
              if (0 < this.pane.getTabs().size()) {
                  this.pane.getTabs().remove(0);
                  try {
                      int[] array = new int[1024];
                      while (true) {
                          array = new int[array.length << 1];
                      }
                  }
                  catch (OutOfMemoryError error) {
                      System.gc();
                  }
                  Platform.runLater(this);
              }
              else {
                  Platform.exit();
              }
          }
      }

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            malenkov Sergey Malenkov (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved:
              Imported: