From d92073cacff6056cc9282589c059d14cd57f2d82 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Wed, 28 Aug 2024 09:39:04 -0700 Subject: [PATCH] Add note about widgets. (#244) --- doc/leak_tracking/TROUBLESHOOT.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/leak_tracking/TROUBLESHOOT.md b/doc/leak_tracking/TROUBLESHOOT.md index 464da1c5..2e91baab 100644 --- a/doc/leak_tracking/TROUBLESHOOT.md +++ b/doc/leak_tracking/TROUBLESHOOT.md @@ -20,13 +20,16 @@ Follow the rules to avoid/fix notGCed and notDisposed leaks: 4. **Weak referencing**. Non-owners should either link the object with WeakReference, or make sure to release the references before the owner disposed the object. -A test specific rule: +**Flutter specific rules:** +1. If a widget creates disposables (like controller), it should be stateful, to be able to dispose the disposables. + +**Test specific rules:** 1. If your test creates a disposable object, it should dispose it in `tearDown`, so that test failure does not result in a leak: -```dart -final FocusNode focusNode = FocusNode(); -addTearDown(focusNode.dispose()); -``` + ```dart + final FocusNode focusNode = FocusNode(); + addTearDown(focusNode.dispose()); + ``` ## Known simple cases