On Mon, 18 Dec 2023 13:18:02 GMT, Johan Vos <j...@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

Reply via email to