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

Leak in TabPane's tabs menu

    XMLWordPrintable

Details

    Description

      Run the application below with a profiler attached. Make sure the window is narrow enough for the tabs menu to appear. Open and close the tabs menu, then close all tabs except one, then make a heap dump.

      A typical heap dump is attached as tabs-menu-leak.zip. It shows 7 objects of type javafx.scene.control.Tab (there should be only one). Most of the objects are referenced from TabControlButtons.popup.skin.

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.Label;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.control.TextField;
      import javafx.scene.input.KeyCombination;
      import javafx.stage.Stage;

      public class Test extends Application {

          @Override public void start(Stage stage) {
              TabPane tabs = new TabPane();
              for (int i=0; i<7; i++) {
                  Label label = new Label("Label" + i);
                  Tab tab = new Tab("Tab" + i);
                  tab.setContent(label);
                  tab.setContextMenu(createContextMenu());
                  tabs.getTabs().add(tab);
              }
              stage.setScene(new Scene(tabs));
              stage.sizeToScene();
              stage.show();
          }
          
          ContextMenu createContextMenu() {
              MenuItem item = new MenuItem("Cut");
              item.setAccelerator(KeyCombination.keyCombination("Ctrl+X"));
              item.setOnAction(new EventHandler<ActionEvent>() {
                  public void handle(ActionEvent ev) {}
              });
              return new ContextMenu(item);
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      Attachments

        Issue Links

          Activity

            People

              kwwong Kinsley Wong (Inactive)
              peterz Peter Zhelezniakov
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: