From bfc353252547f027c56e2ea0066274a123e94d66 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 30 Mar 2016 10:48:56 -0700 Subject: [PATCH] Improve setState-after-dispose error message We now explicitly mention the possibility of a memory leak. Fixes #2978 --- .../flutter/lib/src/painting/text_style.dart | 4 ++-- .../flutter/lib/src/widgets/framework.dart | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 2409803881..7e55ba5000 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -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). diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 9462f64ef3..d493685cbd 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -394,13 +394,19 @@ abstract class State { 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;