Skip to content

Fix leaks by disposing in detach - #49999

Closed
creativecreatorormaybenot wants to merge 3 commits into
flutter:masterfrom
creativecreatorormaybenot:fix_leaks
Closed

creativecreatorormaybenot wants to merge 3 commits into
flutter:masterfrom
creativecreatorormaybenot:fix_leaks

Conversation

@creativecreatorormaybenot

Copy link
Copy Markdown
Contributor

Description

Fixes #14204.

Tests

I have no idea how to test this - if the existing tests pass, this should be fine I reckon. However, I can add tests if someone can tell me how this would be done.

Checklist

  • 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 read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • 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

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Feb 3, 2020
@fluttergithubbot

Copy link
Copy Markdown
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

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

@creativecreatorormaybenot

Copy link
Copy Markdown
Contributor Author

cc @Hixie

Can you help me regarding tests?

@creativecreatorormaybenot

Copy link
Copy Markdown
Contributor Author

Cannot fix the leaks for _RenderSlider because the Slider has correct animations when reparented test in test/material/slider_test.dart prevents disposing the gesture recognizers..

@creativecreatorormaybenot creativecreatorormaybenot changed the title Fix leaks by disposing gesture recognizers in detach Fix leaks by disposing in detach Feb 3, 2020
@Hixie

Hixie commented Feb 22, 2020

Copy link
Copy Markdown
Contributor

It turns out that these aren't actually leaks... with the animation controller, the render object starts and stops it on attach/detach already, so there's no resources being consumed while the render object is detached.

For the gesture recognizer it's a bit trickier. We can't do the solution that's in this PR because attach/detach happens during GlobalKey reparenting, so for example if someone were to move the Slider around the tree while the finger was down, it would cancel the gesture if we were to dispose/recreate the recognizers.

On the other hand, it's true that currently if you put your finger down, then the Slider goes away, then keep moving your finger, the recognizer will keep tracking the finger and may even interfere with the arena if there's other things trying to win the gesture. I'm not 100% sure how to address this, gesture recognizers aren't really compatible with the render object lifecycle... we could move the objects up to the State I guess, and pass them down to the _CupertinoSwitchRenderObjectWidget. The State's dispose is not called during GlobalKey reparenting. The other option would be to add a dispose method to _CupertinoSwitchRenderObjectWidget and have the RenderObjectWidget call it, as a special case for Slider.

We should audit the rest of the code to see if other widgets have these problems.

@Hixie

Hixie commented Feb 22, 2020

Copy link
Copy Markdown
Contributor

BTW, re tests: leaks in AnimationControllers are already checked for by the test framework, so to see if there's a leak you need but instantiate and initialize the leaking owner (the render object here, attaching it being the key), then dispose of it (detach it, in the case of render objects). For GestureRecognizers there's no particularly good way to test if they've been disposed currently. I would focus on what the symptoms would be... e.g. attach the render object (pump a frame with the widget), start a gesture but don't complete it, detach the render object (pump a new frame with different widgets), and see if the pointer router table is empty, or the gesture arenas are empty, or something like that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TapGestureRecognizer leaked by _RenderSlider and _RenderRangeSlider

4 participants