Skip to content

Fix two memory leaks in InkWell and ObservableList#38767

Closed
ds84182 wants to merge 1 commit intoflutter:masterfrom
ds84182:memory_leaks
Closed

Fix two memory leaks in InkWell and ObservableList#38767
ds84182 wants to merge 1 commit intoflutter:masterfrom
ds84182:memory_leaks

Conversation

@ds84182
Copy link
Contributor

@ds84182 ds84182 commented Aug 18, 2019

Description

Found this when using heap snapshots in Observatory to track where Image objects were being leaked.

In InkWell, the highlight mode listener was being added multiple times (every time a dependency updated). This caused a leak because the number of removals did not equal the number of additions.

Then in ObservableList, when items are removed from the list the set is not cleared, even though the set will be cleared and repopulated during the next call to contains. This caused a leak because removed items technically were not removed. This caused entire TransitionRoutes to leak in a chain.

This fixes the last issues I had with image loading in Flutter.

Related Issues

N/A

Tests

I added the following tests:

None, I don't think there's a good way to test memory leaks right now.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

Found this when using heap snapshots in Observatory to track where Image objects were being leaked.

In InkWell, the highlight mode listener was being added multiple times (every time a dependency updated). This caused a leak because the number of removals did not equal the number of additions.

Then in ObservableList, when items are removed from the list the set is not cleared, even though the set will be cleared and repopulated during the next call to `contains`. This caused a leak because removed items technically were not removed. This caused entire TransitionRoutes to leak in a chain.

This fixes the last issues I had with image loading in Flutter.
@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 18, 2019
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. While there are exceptions to this rule, if this patch modifies code it is probably not an exception.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ds84182 ds84182 changed the title Fix two memory leaks Fix two memory leaks in InkWell and ObservableList Aug 18, 2019
@gspencergoog
Copy link
Contributor

@ds84182 Is it OK with you if I merge these fixes into my HighlightMode re-land PR?

@gspencergoog
Copy link
Contributor

(since it was reverted, you'd have to wait until after I commit anyhow)

@ds84182
Copy link
Contributor Author

ds84182 commented Aug 31, 2019 via email

@gspencergoog
Copy link
Contributor

Closing because these fixes are incorporated in #39589

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants