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

TabPaneSkin memory leak on replacing selectionModel

XMLWordPrintable

      title says it all :) Once a skin has been attached to the control, replacing the control's selectionModel keeps a reference to the old selectionModel's selectedItem.

      the offending lines in TabPaneSkin constructor (commenting them will let the test pass):
              registerChangeListener(control.getSelectionModel().selectedItemProperty(), e -> {
                  isSelectingTab = true;
                  selectedTab = getSkinnable().getSelectionModel().getSelectedItem();
                  getSkinnable().requestLayout();
              });


      Failing test case (in SelectionFocusModelTest that's added in the fix for JDK-8241455, this method effectively ignored until this is fixed)

          @Test
          public void testTabPaneSelectionModel() {
              TabPane control = new TabPane();
              ObservableList<String> data = FXCollections.observableArrayList("Apple", "Orange", "Banana");
              data.forEach(text -> control.getTabs().add(new Tab("text")));
              WeakReference<SelectionModel<?>> weakRef = new WeakReference<>(control.getSelectionModel());
              SingleSelectionModel<Tab> replacingSm = TabPaneShim.getTabPaneSelectionModel(control);
              showControl(control);
              control.setSelectionModel(replacingSm);
              attemptGC(weakRef, 10);
              assertNull("selectionModel must be gc'ed", weakRef.get());
          }

            arapte Ambarish Rapte
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: