-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix DraggableScrollableSheet leaks Ticker #102916
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
Fix DraggableScrollableSheet leaks Ticker #102916
Conversation
| ballisticController.dispose(); | ||
| if (_ballisticControllers.contains(ballisticController)) { | ||
| _ballisticControllers.remove(ballisticController); | ||
| ballisticController.dispose(); |
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.
This should be outside of the if statement.
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.
@dnfield
Thanks for reviewing this PR.
In some edge cases (the one in #101061, which is also the one in the test I added with this PR), code in whenCompleteOrCancel might be called after _DraggableScrollableSheetScrollPosition.dispose. If I kept this line outside the if statement it would throw an error about the AnimationController being already disposed.
To avoid this error, I put this line in the if statement and in _DraggableScrollableSheetScrollPosition.dispose I add a call to _ballisticControllers.clear() so if an AnimationController ends just after the call to _DraggableScrollableSheetScrollPosition.dispose it is no more in _ballisticControllers and ballisticController.dispose won’t be called as it is in the if statement. If the AnimationController ends before, it is still in _ballisticControllers and it will be disposed by this line (and removed from _ballisticControllers so we won't try to dispose it again in _DraggableScrollableSheetScrollPosition.dispose)
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.
Ahh ok, thanks, that makes sense.
Description
_DraggableScrollableSheetScrollPosition.goBallisticcreates new AnimationControllers but doesn’t always dispose them. It disposes AnimationControllers when the animation is stopped or canceled. If theDraggableScrollableSheetis disposed, while some AnimationControllers are running, some Tickers leak.The solution is similar to the one in #102504
Related Issue
Fixes #101061
Tests
Add one test in
draggable_scrollable_sheet_test.dartPre-launch Checklist
///).