Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Jun 27, 2024
1 parent 4a9cbad commit b8e174a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ examples/**/.metadata

# OS
.DS_Store
logs/
18 changes: 16 additions & 2 deletions doc/leak_tracking/TROUBLESHOOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,24 @@ Add it to:
* `tearDown` to optimize for test isolation

Sometimes `imageCache.clear()` does not dispose the images handle, but schedules disposal
to happen after the rendering cycle completes.
to happen after the rendering cycle completes.
If this is a case, `imageCache.clear()` needs to happen as last statement of the test,
instead of in tear down, to allow the cycles to happen.

### 4. The test throws flutter exception

Widget states are not disposed by test framework in case of exception.

So, if your test tests a failure, opt it out of leak tracking:


```
testWidgets('async onInit throws FlutterError',
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), // leaking by design because of exception
(WidgetTester tester) async {
...
```

## Get additional information

To understand the root cause of a memory leak, you may want to gather additional information.
Expand Down Expand Up @@ -223,4 +237,4 @@ Images in Flutter have an unusual lifecycle:
creation of their native part is not detectable as happening in a test helper.

3. Images are cashed and reused that improves test performance. So, `tearDownAll(imageCache.clear)`
will help if leaks are caused by test code.
will help if leaks are caused by test code.

0 comments on commit b8e174a

Please sign in to comment.