Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain exceptions. #238

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.