RFR: [WIP] 8319779: SystemMenu: memory leak due to listener never being removed [v4]

John Hendrikx jhendrikx at openjdk.org
Tue Dec 19 09:28:56 UTC 2023


On Mon, 18 Dec 2023 13:18:02 GMT, Johan Vos <jvos at openjdk.org> wrote:

>> A listener was added but never removed.
>> This patch removes the listener when the menu it links to is cleared. Fix for https://bugs.openjdk.org/browse/JDK-8319779
>
> Johan Vos has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix more memoryleaks due to listeners never being unregistered.

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/GlassSystemMenu.java line 218:

> 216:         mb.textProperty().addListener(new WeakInvalidationListener(valueModel -> glassMenu.setTitle(parseText(mb))));
> 217:         mb.disableProperty().addListener(new WeakInvalidationListener(valueModel -> glassMenu.setEnabled(!mb.isDisable())));
> 218:         mb.mnemonicParsingProperty().addListener(new WeakInvalidationListener(valueModel -> glassMenu.setTitle(parseText(mb))));

Isn't this the classic mistake being made with weak listeners where you are wrapping a listener, but then are not referring it?  The inner listener (which is created on the fly) is only weakly referenced, and so can be GC'd  immediately.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1283#discussion_r1431137217


More information about the openjfx-dev mailing list