JDK-8244657 : ChoiceBox/ToolBarSkin: misbehavior on switching skin
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: openjfx14
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-05-08
  • Updated: 2020-05-31
  • Resolved: 2020-05-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
openjfx15Fixed
Related Reports
Blocks :  
Relates :  
Description
turned up in binch testing (see JDK-8244531), the issues are

- memory leak
- NPE thrown in old skin if items added after replacing the skin

// test snippets 

    @Test
    public void testMemoryLeakAlternativeSkin() {
        installDefaultSkin(control);
        WeakReference<?> weakRef = new WeakReference<>(control.getSkin());
        assertNotNull(weakRef.get());
        setAlternativeSkin(control);
        attemptGC(weakRef);
        assertEquals("Skin must be gc'ed", null, weakRef.get());
    }
    
    @Test
    public void testSideEffectAlternativeSkin() {
        if (sideEffect == null) return;
        installDefaultSkin(control);
        setAlternativeSkin(control);
        sideEffect.accept(control);
    }
    
with sideEffect:

    (Consumer<Control>) c -> {
          ChoiceBox box = (ChoiceBox) c;
                 box.getItems().add("added");
     }

culprits are manually added listeners to items / selectionModel.selectedIndex that are not removed

Fix is to remove:

    /** {@inheritDoc} */
    @Override public void dispose() {
        // removing the content listener fixes NPE from listener
        if (choiceBoxItems != null) {
            choiceBoxItems.removeListener(weakChoiceBoxItemsListener);
            choiceBoxItems = null;
        }
        // removing the path listener fixes the memory leak on replacing skin
        if (selectionModel != null) {
            selectionModel.selectedIndexProperty().removeListener(selectionChangeListener);
            selectionModel = null;
        }
       ...
 


Comments
Changeset: 1ab653cb Author: Jeanette Winzenburg <fastegal@openjdk.org> Committer: Ajit Ghaisas <aghaisas@openjdk.org> Date: 2020-05-30 09:13:44 +0000 URL: https://git.openjdk.java.net/jfx/commit/1ab653cb
30-05-2020

ToolBarSkin has very similar misbehavior, 2 listeners that are not removed: - listener to itemsProperty -> NPE when adding items after switching skin - manually added listener to the control's focusedProperty -> memory leak similar fix: - remove listChangeListener in dispose - wire focusListener with skin api
26-05-2020