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

8293444: Creating ScrollPane with same content component causes memory leak #900

Closed

Conversation

andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Sep 15, 2022

Using Weak*Listeners eliminates the memory leak.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8293444: Creating ScrollPane with same content component causes memory leak

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/900/head:pull/900
$ git checkout pull/900

Update a local copy of the PR:
$ git checkout pull/900
$ git pull https://git.openjdk.org/jfx pull/900/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 900

View PR using the GUI difftool:
$ git pr show -t 900

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/900.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 15, 2022

👋 Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review September 15, 2022 21:08
@openjdk openjdk bot added the rfr Ready for review label Sep 15, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 15, 2022

Webrevs

@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented Sep 16, 2022

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

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

This looks like it will eliminate the leak. Using weak listeners like this follows the same pattern as used by some of the other skins. I'll review and test it next week.

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.

Fix looks good,
Providing some minor comments for test.

@FlorianKirmaier
Copy link
Member

A small comment about the memory test with JMemoryBuddy.
Instead of this:

<code>
List<WeakReference> refs = ...
WeakReference a = b;
refs.add(a);
<code>
for (WeakReference<ScrollPane> ref : refs) {
       JMemoryBuddy.checkCollectable(ref);
}

It is more readable this way:

JMemoryBuddy.memoryTest(checker -> {
  <code>
  checker.setAsReferenced(objects);
  checker.assertCollectable(b);
});

@andy-goryachev-oracle
Copy link
Contributor Author

A small comment about the memory test with JMemoryBuddy.

Thank you for suggestion. I will definitely use it in other tests!
Here it won't work because in the part of the test one instance is expected to remain uncollected.

@FlorianKirmaier
Copy link
Member

FlorianKirmaier commented Sep 28, 2022

if you use checker.setAsReferenced(object) then the specified object won't be collected for the current test.
And there is also the statement assertNotCollectable() to check the reverse.

The method "checkCollectable/assertCollectable" is very slow in the negative case (but reliable in the positive case)
The method "checkNotCollectable/<assertNotCollectable" should be used, if it's expected that the object is not collectable - otherwise the test will be quite slow.

@andy-goryachev-oracle
Copy link
Contributor Author

@FlorianKirmaier :
I am not sure if using JMemoryBuddy.memoryTest results in a clearer or more concise code, given the nature of testScrollPaneObjLeakWhenUsedSameContent().

BTW, MemoryTestAPI names are a bit confusing: "assert*Collectable" suggests assertion is done at the point when these calls are made, though it looks like they just add a reference the an internal list. Also, assertCollectable might want to skip creation of a WeakReference if the object passed to it is already a WeakReference.

With your permission, I would like to keep this test as is.

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.

@FlorianKirmaier
Copy link
Member

Of course, you can keep it this way.

The point of JMemoryBuddy.memoryTest is, that the user doesn't have to fiddle around with WeakReferences.
For the record, your test might look like this (not tested):

    @Test
    public void testScrollPaneObjLeakWhenUsedSameContent() {
        JMemoryBuddy.memoryTest(() -> {
            BorderPane bp = new BorderPane();

            Stage stage = new Stage();
            stage.setScene(new Scene(bp));
            stage.show();

            Label content = new Label("content");

            ScrollPane sp1 = new ScrollPane(content);
            bp.setCenter(sp1);
            Toolkit.getToolkit().firePulse();

            ScrollPane sp2 = new ScrollPane(content);
            bp.setCenter(sp2);
            Toolkit.getToolkit().firePulse();

            bp.setCenter(null);
            Toolkit.getToolkit().firePulse();

            // When the label is still referenced, then only one ScrollPane should stay which is its parent
            checker.setAsReferenced(label)
            checker.assertCollectable(sp1)
            checker.assertNotCollectable(sp2)
        });
    }

    @Test
    public void testScrollPaneObjLeakWhenUsedSameContent() {
        JMemoryBuddy.memoryTest(() -> {
            BorderPane bp = new BorderPane();

            Stage stage = new Stage();
            stage.setScene(new Scene(bp));
            stage.show();

            Label content = new Label("content");

            ScrollPane sp1 = new ScrollPane(content);
            bp.setCenter(sp1);
            Toolkit.getToolkit().firePulse();

            ScrollPane sp2 = new ScrollPane(content);
            bp.setCenter(sp2);
            Toolkit.getToolkit().firePulse();

            bp.setCenter(null);
            Toolkit.getToolkit().firePulse();

            // IF our label is gone, both scrollpanes shold be collectable
            checker.assertCollectable(sp1)
            checker.assertCollectable(sp2)
        });
    }

I think only the first test is the important one.

@andy-goryachev-oracle
Copy link
Contributor Author

Thank you for clarifications, @FlorianKirmaier

Copy link
Member

@kevinrushforth kevinrushforth 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.

@openjdk
Copy link

openjdk bot commented Oct 4, 2022

@andy-goryachev-oracle 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:

8293444: Creating ScrollPane with same content component causes memory leak

Reviewed-by: kcr, arapte

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 8 new commits pushed to the master branch:

  • cc00c8d: 8293795: [Accessibility] [Win] [Narrator] Exceptions when deleting text with continous key press in TextArea and TextField
  • 35675c8: 8293971: Loading new Media from resources can sometimes fail when loading from FXML
  • 03569b7: 8293883: Add tests/.classpath (Eclipse)
  • 82db6cc: 8289541: Update ICU4C to 71.1
  • 7c6a54d: 8293839: Documentation memory consistency effects of runLater
  • a27840e: 8293368: GitHub Workflows security hardening
  • 5e4552d: 8089280: horizontal scrollbar should never become visible in TableView with constrained resize policy
  • cef583e: 8293214: Add support for Linux/LoongArch64

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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.

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 (@kevinrushforth, @arapte) 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 Oct 4, 2022
@andy-goryachev-oracle
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Ready to sponsor label Oct 4, 2022
@openjdk
Copy link

openjdk bot commented Oct 4, 2022

@andy-goryachev-oracle
Your change (at version 0b22c2c) is now ready to be sponsored by a Committer.

@kevinrushforth
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 4, 2022

Going to push as commit 337c781.
Since your change was applied there have been 8 commits pushed to the master branch:

  • cc00c8d: 8293795: [Accessibility] [Win] [Narrator] Exceptions when deleting text with continous key press in TextArea and TextField
  • 35675c8: 8293971: Loading new Media from resources can sometimes fail when loading from FXML
  • 03569b7: 8293883: Add tests/.classpath (Eclipse)
  • 82db6cc: 8289541: Update ICU4C to 71.1
  • 7c6a54d: 8293839: Documentation memory consistency effects of runLater
  • a27840e: 8293368: GitHub Workflows security hardening
  • 5e4552d: 8089280: horizontal scrollbar should never become visible in TableView with constrained resize policy
  • cef583e: 8293214: Add support for Linux/LoongArch64

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 4, 2022
@openjdk openjdk bot closed this Oct 4, 2022
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review sponsor Ready to sponsor labels Oct 4, 2022
@openjdk
Copy link

openjdk bot commented Oct 4, 2022

@kevinrushforth @andy-goryachev-oracle Pushed as commit 337c781.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8293444.leak branch October 4, 2022 18:15
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
Development

Successfully merging this pull request may close these issues.

4 participants