From 2152aab56084c5a7b568f0ea454ce12289bb0ad8 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Fri, 21 Jul 2023 09:02:37 -0700 Subject: [PATCH] Add details about hidden leaks. (#97) --- doc/DETECT.md | 2 +- doc/TROUBLESHOOT.md | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/DETECT.md b/doc/DETECT.md index cf27f050..35c2db8c 100644 --- a/doc/DETECT.md +++ b/doc/DETECT.md @@ -61,7 +61,7 @@ Leak tracker does not work for web platform. ### By tracked classes The leak tracker will catch leaks only for instrumented -objects (See [concepts](#leak-tracking-concepts) for details). +objects (See [concepts](CONCEPTS.md) for details). However, the good news is: diff --git a/doc/TROUBLESHOOT.md b/doc/TROUBLESHOOT.md index 61b7402a..52ff760b 100644 --- a/doc/TROUBLESHOOT.md +++ b/doc/TROUBLESHOOT.md @@ -98,9 +98,29 @@ If `A` and `B` are still needed, `B` should assign null to the variable that ref Otherwise, the reference to the first non-needed object on the path (`staticX`, `A` or `B`) should be released. ``` -staticX -> A -> B -> disposedD +root -> staticX -> A -> B -> disposedD ``` +The leak tracker does not detect all leaks, only the leaks of objects +[it explicitly is tracking](https://github.com/dart-lang/leak_tracker/blob/main/doc/DETECT.md#by-tracked-classes). +When fixing detected leaks, make sure to look for other objects that may have been leaked without being visible to the tracker. + +To fix all leaks, you need to release closest to the root object on retaining path +(first check `staticX`, then `A`, then `B`), that is not needed any more. All objects referenced from it will +also become unreachable, and thus available for garbage collection. + +One of signs that some leaks still exist is fixing a leak by releasing link to child in the parent's `dispose`, +because link to not needed parent should be released itself, together with its disposal. If +your fix for a leak is like this, you are defenitely hiding leaks of non-tracked objects: + +``` +void dispose() { + _leakTrackedChild!.dispose(); + _leakTrackedChild = null; // Wrong fix! This line hides leaks. +} +``` + + ### 2. More than one closure context If a method contains more than one closures, they share the context and thus all