Commit bfc35325 authored by Adam Barth's avatar Adam Barth

Improve setState-after-dispose error message

We now explicitly mention the possibility of a memory leak.

Fixes #2978
parent 4df24abb
......@@ -59,8 +59,8 @@ class TextStyle {
/// The height of this text span, as a multiple of the font size.
///
/// If applied to the root [TextSpan], this value sets the line height, which
/// is the minimum distance between each text baselines, as multiple of the
/// font size.
/// is the minimum distance between subsequent text baselines, as multiple of
/// the font size.
final double height;
/// The decorations to paint near the text (e.g., an underline).
......
......@@ -394,13 +394,19 @@ abstract class State<T extends StatefulWidget> {
if (_debugLifecycleState == _StateLifecycle.defunct) {
throw new FlutterError(
'setState() called after dispose(): $this\n'
'This error happens if you call setState() on State object for a widget that\n'
'no longer appears in the widget tree (e.g., whose parent widget no longer\n'
'includes the widget in its build). This error can occur when code calls\n'
'setState() from a timer or an animation callback. The preferred solution is\n'
'to cancel the timer or stop listening to the animation in the dispose()\n'
'callback. Another solution is to check the "mounted" property of this\n'
'object before calling setState() to ensure the object is still in the tree.'
'This error happens if you call setState() on State object for a widget that '
'no longer appears in the widget tree (e.g., whose parent widget no longer '
'includes the widget in its build). This error can occur when code calls '
'setState() from a timer or an animation callback. The preferred solution is '
'to cancel the timer or stop listening to the animation in the dispose() '
'callback. Another solution is to check the "mounted" property of this '
'object before calling setState() to ensure the object is still in the '
'tree.\n'
'\n'
'This error might indicate a memory leak if setState() is being called '
'because another object is retaining a reference to this State object '
'after it has been removed from the tree. To avoid memory leaks, '
'consider breaking the reference to this object during dipose().'
);
}
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment