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

Jose Pereda jpereda at openjdk.org
Wed Dec 13 09:16:55 UTC 2023


On Mon, 20 Nov 2023 08:00:58 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:
> 
>   process reviewers comments

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

> 187: 
> 188:     private ListChangeListener<MenuItemBase> createListener(final Menu glassMenu) {
> 189:         return (ListChangeListener.Change<? extends MenuItemBase> change) -> {

In this listener, when there are items removed that are `Menu`s, we should also call  `clearMenu`:

             if (i >= 0 && menuItemList.size() > i) {
                        glassMenu.remove(i);
+                        Object item = menuItemList.get(i);
+                        if (item instanceof Menu menu) {
+                                clearMenu(menu);
+                        }
                 }


Otherwise, they won't be removed from the new maps.

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

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


More information about the openjfx-dev mailing list