Skip to content
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

8241455: Memory leak on replacing selection/focusModel #148

Closed
wants to merge 3 commits into from

Conversation

kleopatra
Copy link
Collaborator

@kleopatra kleopatra commented Mar 23, 2020

Several controls with selection/focusModels leave memory leaks on replacing the model.

Added tests for all such, those for the misbehaving models fail before and pass after the fix.

for convenience, the bug reference https://bugs.openjdk.java.net/browse/JDK-8241455


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8241455: Memory leak on replacing selection/focusModel

Reviewers

  • Ambarish Rapte (arapte - Reviewer)
  • Ajit Ghaisas (aghaisas - Reviewer)

Download

$ git fetch https://git.openjdk.java.net/jfx pull/148/head:pull/148
$ git checkout pull/148

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 23, 2020

👋 Welcome back fastegal! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request.

@openjdk openjdk bot added the rfr Ready for review label Mar 23, 2020
@mlbridge
Copy link

mlbridge bot commented Mar 23, 2020

Webrevs

@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented Mar 23, 2020

@kevinrushforth
The number of required reviews for this PR is now set to 2 (with at least 1 of role reviewers).

@kevinrushforth
Copy link
Member

I have basically the same comment / question as I asked in #147

In general, there are two approaches to avoiding listener-related memory leaks. One is to use a WeakListener; the other is to explicitly remove the listener when the object is removed or otherwise no longer needed.

Using a WeakListener is certainly easier, but runs the risk of the listener being removed too early and not cleaning up after itself. I'm not suggesting that's the case here, but it is worth looking at.

@kevinrushforth
Copy link
Member

kevinrushforth commented Mar 23, 2020

@arapte @aghaisas - Can you both review this?

@kleopatra
Copy link
Collaborator Author

I would like to widen the issue (and change this pull request accordingly) to include memory leaks of introduced selection- and focusModels in other controls that are caused by the basically same reason, that is strong references via listeners to controls' properties. The fix would be the same as well, that is wrap the listeners into weakXXListeners and register these.

The models suggested to include here:

  • TreeView: selection- and focusModel
  • TreeTableView: focusModel
  • TabPane: selectionModel

Not included would be memory leaks introduced by whacky listening of ChoiceBoxSkin and TabPaneSkin to properties of the selectionModel. The former will (most probably) be fixed as a side-effect of https://bugs.openjdk.java.net/browse/JDK-8087555 (which I intend to take, if Ajit agrees :), will open a separate issue for the latter.

The extended fix here will have tests for replacing selection/focusModels with/out a skin registered for all controls having the respective models.

Not entirely certain about the formal procedure (locally fix and tests are - nearly, pending some cleanup - ready). Simply change titles, rebase and push again?

@kevinrushforth
Copy link
Member

If Ambarish and Ajit are OK with this, then the procedure would be as you guessed: change the title of both the JBS bug and then this PR and push your new fix (with or without rebasing would be fine).

@arapte
Copy link
Member

arapte commented Mar 26, 2020

That is good idea to combine all similarly affected selection models. I think rebase won't be required just updating the PR with more commits should be good enough.

@aghaisas
Copy link
Collaborator

Not included would be memory leaks introduced by whacky listening of ChoiceBoxSkin and TabPaneSkin to properties of the selectionModel. The former will (most probably) be fixed as a side-effect of https://bugs.openjdk.java.net/browse/JDK-8087555 (which I intend to take, if Ajit agrees :), will open a separate issue for the latter.

Please go ahead and take it up. Thanks!

Regarding combining other issue. I am OK with the idea.
Bug Title, Bug Description and PR Title should be updated accordingly.

@kleopatra kleopatra changed the title 8241455: ChoiceBox - memory leak on replacing selectionModel 8241455: Memory leak on replacing selection/focusModel Mar 27, 2020
Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me.
Similar to Skin classes the listeners here are also not explicitly removed.
But I don't see any problematic scenario even if the listeners of an old Model are executed before it gets GCed.
Suggested minor changes in test.

stage = new Stage();
stage.setScene(scene);
}
root.getChildren().add(node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be good to add a call to root.getChildren().removeAll() before adding the node to root ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be good to add a call to root.getChildren().removeAll() before adding the node to root ?

hmm .. don't think that it's necessary to clear out other children: the thing that actually matters is that the control goes active in the scenegraph and has a skin attached. Can you think of any context where any of the tests might get whacky if there are more than one nodes in the root?

Actually, that's a pattern (*cough, read that's more or less c&p'ed) I use in other tests, where it sometimes is allowed and expected that there are more than one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that It would not cause any problem in test execution.

Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

@openjdk
Copy link

openjdk bot commented Apr 3, 2020

@kleopatra This change now passes all automated pre-integration checks. When the change also fulfills all project specific requirements, type /integrate in a new comment to proceed. After integration, the commit message will be:

8241455: Memory leak on replacing selection/focusModel

Reviewed-by: arapte, aghaisas
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /solves command.

Since the source branch of this PR was last updated there have been 10 commits pushed to the master branch. Since there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate 5906521cf2a605014f947f3216f5d1906bb8859d.

As you do not have Committer status in this project, an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@arapte, @aghaisas) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Ready to be integrated label Apr 3, 2020
@kleopatra
Copy link
Collaborator Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 3, 2020

@kleopatra
Your change (at version 8bed244) is now ready to be sponsored by a Committer.

@openjdk openjdk bot added the sponsor Ready to sponsor label Apr 3, 2020
@arapte
Copy link
Member

arapte commented Apr 6, 2020

/sponsor

@openjdk openjdk bot closed this Apr 6, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Ready to sponsor labels Apr 6, 2020
@openjdk
Copy link

openjdk bot commented Apr 6, 2020

@arapte @kleopatra The following commits have been pushed to master since your change was applied:

  • 5906521: 8241370: Crash in JPEGImageLoader after fix for JDK-8212034
  • 159f651: 8240542: Switch FX build to use JDK 14 as boot JDK
  • 6d098fe: 8234959: FXMLLoader does not populate ENGINE_SCOPE Bindings with FILENAME and ARGV
  • d7f13f4: 8089828: RTL Orientation, the flag of a mnemonic is not placed under the mnemonic letter.
  • 9ecc107: 8240539: Upgrade gradle to version 6.3
  • f3a3ea0: 8234471: Canvas in webview displayed with wrong scale on Windows
  • d12e71c: 8241474: Build failing on Ubuntu 20.04
  • 2a7ab36: 8089134: [2D traversal, RTL] TraversalEngine only handles left/right key traversal correctly in RTL for top-level engine in ToolBar
  • 2aa8218: 8235480: Regression: [RTL] Arrow keys navigation doesn't respect TableView orientation
  • e9c6119: 8240692: Cleanup of the javafx property objects

Your commit was automatically rebased without conflicts.

Pushed as commit 560ef17.

@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Apr 6, 2020
@kleopatra kleopatra deleted the bug-fix-JDK-8241455 branch May 5, 2020 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
4 participants