-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Dispose thumbPainter in Switch to avoid crash #81089
Conversation
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.
LGTM, have a nice weekend
This pull request is not suitable for automatic merging in its current state.
|
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.
LGTM
|
||
@override | ||
void dispose() { | ||
_cachedThumbPainter?.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.
Should we null _cachedThubPainter and other internal fields so that holding a reference to a disposed _MaterialSwitch doesn't prevent the image from being GC'd?
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.
Good idea, will make that change.
8531cda
to
21cc219
Compare
21cc219
to
abe6c52
Compare
Fixes b/186203085
The thumpPainter is invoking its onChanged callback (_handleDecorationChanged) when the given ImageProvider finally completes to trigger a repaint. If the Switch is already disposed at that moment, the
notifyListeners
call in_handleDecorationChanged
crashes. To avoid all that, the thumbPainter must be disposed when the Switch is disposed or when it is replaced with another painter.