Repository navigation
Dispose timeline and memory controllers properly - #1523
Conversation
| try { | ||
| _listenables[i].removeListener(_listeners[i]); | ||
| } on FlutterError catch (e) { | ||
| // If the listenable has already been disposed, it will throw an error |
There was a problem hiding this comment.
we should catch the underlying error instead of hiding it with a try catch block.
There was a problem hiding this comment.
can we fix the order of execution instead so that the listeners are removed before the listenables are disposed?
There was a problem hiding this comment.
I like both of these ideas a lot.
we should catch the underlying error instead of hiding it with a try catch block.
The underlying error can change. In debug mode it will be a FlutterError thrown by an assert. In release mode, it will be a null pointer error because the underlying notifier's _listeners list is null.
can we fix the order of execution instead so that the listeners are removed before the listenables are disposed?
We can by overriding the InheritedElement behavior. I originally felt like that was going to be a bit too much boilerplate in the Controllers class, and it will be a few lines more of code than the try/catch. However, having slept on it I feel a lot better about delaying the disposal than I feel about this try/catch.
oldWidget only exists as a parameter to the didUpdateWidget call. We have to cache something intermediately to dispose of the data later.
Yes. Element life cycles are strictly greater than widget/state life cycles. When the element is removed from the tree, all the widgets that depended on it will be gone. |
Great! |

This involves a change to the autodispose mixin that allows it to safely remove a callback from an already-disposed listener.