From 7b81bbd5d1cd178a951b89a815f505fdcbc243d9 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 12 Sep 2022 11:31:48 -0700 Subject: [PATCH] Add doc note about when to dispose TextPainter (#111403) --- packages/flutter/lib/src/painting/text_painter.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index 5cf0433a6b..9a0fb8b3d9 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -168,6 +168,13 @@ class _CaretMetrics { /// /// 3. Call [paint] as often as desired to paint the paragraph. /// +/// 4. Call [dispose] when the object will no longer be accessed to release +/// native resources. For [TextPainter] objects that are used repeatedly and +/// stored on a [State] or [RenderObject], call [dispose] from +/// [State.dispose] or [RenderObject.dispose] or similar. For [TextPainter] +/// objects that are only used ephemerally, it is safe to immediately dispose +/// them after the last call to methods or properties on the object. +/// /// If the width of the area into which the text is being painted /// changes, return to step 2. If the text to be painted changes, /// return to step 1.