RFR: 8241455: ChoiceBox - memory leak on replacing selectionModel

Kevin Rushforth kcr at openjdk.java.net
Mon Mar 23 23:49:37 UTC 2020


On Mon, 23 Mar 2020 16:32:16 GMT, Jeanette Winzenburg <fastegal at openjdk.org> wrote:

> ChoiceBox leaves a memory leak when replacing the selectionModel. Culprit is ChoiceBoxSelectionModel which registers
> listener with strong references. Fix is to change these to weak references.
> Added test that fails before and passes after the test.
> 
> for convenience, the bug reference https://bugs.openjdk.java.net/browse/JDK-8241455

I have basically the same comment / question as I asked in #147

In general, there are two approaches to avoiding listener-related memory leaks. One is to use a WeakListener; the other
is to explicitly remove the listener when the object is removed or otherwise no longer needed.

Using a WeakListener is certainly easier, but runs the risk of the listener being removed too early and not cleaning up
after itself. I'm not suggesting that's the case here, but it is worth looking at.

-------------

PR: https://git.openjdk.java.net/jfx/pull/148


More information about the openjfx-dev mailing list