-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8208088: Memory Leak in ControlAcceleratorSupport #429
Conversation
👋 Welcome back arapte! A progress list of the required criteria for merging this PR into |
Webrevs
|
/reviewers 2 |
Is there a unit test that can validate this fix? |
@kevinrushforth |
I have added a unit test using a new shim class. Test verifies size of the map that is added as part of this fix. |
The new unit test fails on all platforms, as you can see from the GitHub actions log:
|
The test failed because, change listeners added by other tests get accumulated in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good.
The test looks OK as far as it goes, although I note that it is testing for the leak in an indirect way, since it looks at the changeListenerMap
rather than checking the listeners of menuitem.acceleratorProperty()
which is what we really care about. Is there a way to test it more directly? If not then I think this is fine.
...s/javafx.controls/src/test/java/test/javafx/scene/control/ControlAcceleratorSupportTest.java
Outdated
Show resolved
Hide resolved
|
The updated test looks good. I confirm that it fails without the fix and passes with the fix. In order to do that I locally deleted the newly added shim class and comment out all calls to |
I have removed the indirect way, please take a look. |
@arapte This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 22 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
@arapte Since your change was applied there have been 22 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 05ab799. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
After updating to jfx 17, I detected memory leak in my application (every controller that has menu items won't get garbage collected after closing its stage), with visualvm I found it was caused by class ControlAcceleratorSupport. This kind of memory leak doesn't happen on jfx 16, so I guess there is something wrong with this PR. I've created a sample project that could reproduce and verify the memory leak: jfx-test (on git branch ControlAcceleratorSupport). Run command Clicking button After clicking If menu items are set with action listeners, then these listeners also won't be garbage collected, typically these listeners hold references to controllers, which made all closed controllers leaked. This made jfx 17 unusable. |
Could you please report the bug at https://bugreport.java.com/ with a minimum reproducible example (written in Java)? |
I was just going to mention the same thing. See the project README. |
Mailing list message from Daniel Peintner on openjfx-dev: Hi, I don't wanna clutter the list but I noticed this issue also and can point See test here: The test provided fails on JavaFX (v17) and succeeds on v16. Note: The test should be usable "as is" since it uses JMemoryBuddy which is Hope this helps, -- Daniel On Fri, Sep 10, 2021 at 1:40 PM Kevin Rushforth <kcr at openjdk.java.net> |
@Maran23 @kevinrushforth Bug reported via https://bugreport.java.com/bugreport/ with a minimum reproducible example written in Java, internal review ID : 9071415. |
The method
ControlAcceleratorSupport.doAcceleratorInstall(final List<? extends MenuItem> items, final Scene scene)
adds aChangeListener
onMenuItem.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 methodControlAcceleratorSupport.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 onMenu.getItems()
. ThisMenuBarButton
is created byMenuBarSkin
to show aMenu
. ThisMenuBarButton
gets disposed when the relatedMenu
is removed from scenegraph, and so the addedListChangeListener
gets GCed. Hence it is not required to explicitly remove the listener.Added a comment explaining this behavior in place of the TODO.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/429/head:pull/429
$ git checkout pull/429
Update a local copy of the PR:
$ git checkout pull/429
$ git pull https://git.openjdk.java.net/jfx pull/429/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 429
View PR using the GUI difftool:
$ git pr show -t 429
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/429.diff