There is a number of places where various listeners (strong as well as weak) are added, to be later disconnected in one go. For example, Skin implementations use dispose() method to clean up the listeners installed in the corresponding Control (sometimes using LambdaMultiplePropertyChangeListenerHandler class).
This pattern is also used by app developers, but there is no public utility class to do that, so every one must invent their own, see for instance
https://github.com/andy-goryachev/FxTextEditor/blob/master/src/goryachev/fx/FxDisconnector.java
Proposal
It might be beneficial to create a class (ListenerHelper, feel free to suggest a better name) which:
- provides convenient methods like addChangeListener, addInvalidationListener, addWeakChangeListener, etc.
- keeps track of the listeners and the corresponding ObservableValues
- provides a single disconnect() method to remove all the listeners in one go.
- optionally, it should be possible to add a lambda (Runnable) to a group of properties
- optionally, there should be a boolean flag to fire the lambda immediately
- strongly suggest implementing an IDisconnectable functional interface with a single disconnect() method
Make it Public Later
Initially, I think we could place the new class in package com.sun.javafx.scene.control; to be made publicly accessible later.
- blocks
-
JDK-8294589 MenuBarSkin: memory leak when changing skin
- Resolved
-
JDK-8295531 ComboBoxBaseSkin: memory leak when changing skin
- Resolved
-
JDK-8241364 ☂ Cleanup skin implementations to allow switching
- Open
- relates to
-
JDK-8307538 Memory leak in TreeTableView when calling refresh
- Resolved
-
JDK-8295754 PaginationSkin: memory leak when changing skin
- Resolved
-
JDK-8295796 ScrollPaneSkin: memory leak when changing skin
- Resolved
-
JDK-8295806 TableViewSkin: memory leak when changing skin
- Resolved
-
JDK-8295809 TreeTableViewSkin: memory leak when changing skin
- Resolved
-
JDK-8245145 Spinner: throws IllegalArgumentException when replacing skin
- Resolved
-
JDK-8296076 Remove internal class LambdaMultiplePropertyChangeListenerHandler
- Open