RFR: 8208088: Memory Leak in ControlAcceleratorSupport [v3]
Ambarish Rapte
arapte at openjdk.java.net
Tue Mar 23 14:30:56 UTC 2021
> The method `ControlAcceleratorSupport.doAcceleratorInstall(final List<? extends MenuItem> items, final Scene scene)` adds a `ChangeListener` on `MenuItem.acceleratorProperty()`. This listener is not removed when the MenuItem is removed from scenegraph.
> Adding and removing a MenuItem results in multiple copies of the listener added to MenuItem.acceleratorProperty().
>
> Fix is to remove the listener when MenuItem is removed.
> Fix can be verified by checking the number of instances of `ControlAcceleratorSupport.lambda` using _jvisualvm_.
> Without this fix, the number of `ControlAcceleratorSupport.lambda` increase in multiple of number of MenuItems being removed and added back.
> With fix, the count is always same as number of MenuItems in scenegraph.
>
> Also there is another ListChangeListener added to a `ObservableList<MenuItem> items` in the method `ControlAcceleratorSupport.doAcceleratorInstall(final ObservableList<MenuItem> items, final Scene scene)`. There was a TODO note to remove this listener.
> This listener is added on `MenuBarButton.getItems()` and not on `Menu.getItems()`. This `MenuBarButton` is created by `MenuBarSkin` to show a `Menu`. This `MenuBarButton` gets disposed when the related `Menu` is removed from scenegraph, and so the added `ListChangeListener` gets GCed. Hence it is not required to explicitly remove the listener.
> Added a comment explaining this behavior in place of the TODO.
Ambarish Rapte has updated the pull request incrementally with one additional commit since the last revision:
correct test
-------------
Changes:
- all: https://git.openjdk.java.net/jfx/pull/429/files
- new: https://git.openjdk.java.net/jfx/pull/429/files/4ed3f72f..62344c7e
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jfx&pr=429&range=02
- incr: https://webrevs.openjdk.java.net/?repo=jfx&pr=429&range=01-02
Stats: 21 lines in 1 file changed: 12 ins; 0 del; 9 mod
Patch: https://git.openjdk.java.net/jfx/pull/429.diff
Fetch: git fetch https://git.openjdk.java.net/jfx pull/429/head:pull/429
PR: https://git.openjdk.java.net/jfx/pull/429
More information about the openjfx-dev
mailing list