From 269beea5d252a98b8a173be87fbe1587e4f2ce90 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Sun, 4 May 2025 14:45:19 -0700 Subject: [PATCH] Update DETECT.md --- doc/leak_tracking/DETECT.md | 42 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/doc/leak_tracking/DETECT.md b/doc/leak_tracking/DETECT.md index a0b99ebd..a5fb1732 100644 --- a/doc/leak_tracking/DETECT.md +++ b/doc/leak_tracking/DETECT.md @@ -96,11 +96,9 @@ class InstrumentedDisposable { ## See leaks in a running application (experimental) -1. Add [leak_tracker](https://pub.dev/packages/leak_tracker) to `dependencies` in `pubspec.yaml`. +1. Add `leak_tracker: any` to `dependencies` in `pubspec.yaml`. -2. Before `runApp` invocation, enable leak tracking - -3. For Flutter applications, connect to +2. Before `runApp` invocation, enable leak tracking and connect to the Flutter memory allocation events: ```dart @@ -135,25 +133,37 @@ the Flutter memory allocation events: create and dispose any Flutter disposable (for example `FocusNode`), and store the instance in a global array. - To track notGCed leaks, you + NOTE: To track notGCed leaks (experimental feature), you need to enable them: + + ``` + LeakTracking.phase = PhaseSettings( + ignoredLeaks: IgnoredLeaks(experimentalNotGCed: IgnoredLeaksSet()), + ); + ``` 5. Troubleshooting tips: - a. Get the details of the leaks by collecting them - on a button click or on some other event. Then either - analyze the leaks programmatically or print them to the console: + a. To analyze the leaks programmatically run: - ``` - final leaks = await LeakTracking.collectLeaks(); - print(leaks.toYaml(phasesAreTests: false)); - ``` + ``` + final leaks = await LeakTracking.collectLeaks(); + print(leaks.toYaml(phasesAreTests: false)); + ``` + + b. To start collecting creation call stack, update `phase`: + + ```dart + LeakTracking.phase = PhaseSettings( + leakDiagnosticConfig: LeakDiagnosticConfig(collectStackTraceOnStart: true), + ); + ``` - b. To declare all not disposed objects as leaks, invoke `LeakTracking.declareNotDisposedObjectsAsLeaks()` + c. To declare all not disposed objects as leaks, invoke `LeakTracking.declareNotDisposedObjectsAsLeaks()` - c. To add debugging information to an object's record, invoke - `LeakTracking.dispatchObjectTrace(theObject, )` + d. To add debugging information to an object's record, invoke + `LeakTracking.dispatchObjectTrace(theObject, )` - d. To analyze all tracked objects, invoke `LeakTracking.tracked()` + e. To analyze all tracked objects, invoke `LeakTracking.tracked()` ## Limitations