From d65316b6e8541c49b0019ba850a47db7bb5200a0 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Tue, 27 Aug 2024 14:59:55 -0700 Subject: [PATCH] Add note about widgets. --- 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..d833969a 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, it should be stateful, to be able to dispose them. + +**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