examples: fix IndexedStack dispose memory leak#186524
Conversation
Add missing dispose() to _IndexedStackExampleState example. The TextEditingController was created but never disposed. Fixes flutter#186324
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request adds a dispose method to the _IndexedStackExampleState class to ensure the fieldText controller is properly disposed of. Feedback was provided regarding the removal of an unnecessary blank line and the logical ordering of lifecycle methods, suggesting that dispose should be placed before the build method to align with the Flutter style guide.
| @override | ||
| void dispose() { | ||
| fieldText.dispose(); | ||
| super.dispose(); | ||
| } | ||
|
|
There was a problem hiding this comment.
The dispose method contains an unnecessary blank line at the end. Additionally, per the Flutter style guide, lifecycle methods should be ordered logically; dispose is typically placed before the build method. Please remove the extra newline and consider moving the method above build.
| @override | |
| void dispose() { | |
| fieldText.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| void dispose() { | |
| fieldText.dispose(); | |
| super.dispose(); | |
| } |
References
- All Dart code is formatted using
dart format, which removes unnecessary blank lines at the end of class bodies. Also, class members should be ordered logically (e.g., by lifecycle). (link)
|
This PR fixes a memory leak in an example file ( Requesting test exemption because:
Please review and merge. Thanks! |
| ); | ||
| } | ||
| @override | ||
| void dispose() { |
There was a problem hiding this comment.
Does https://github.com/flutter/flutter/blob/master/examples/api/test/widgets/basic/indexed_stack.0_test.dart not run with leak tracking enabled?
Des it fail if you run it with leak tracking enabled, without your change? (and passes with your change)
|
Hi @trippusultan thanks for contributing! We cannot consider this change without having the CLA signed, would you please do that? |
Problem
The IndexedStack example creates a
TextEditingControllerbut never disposes it, causing a memory leak.Solution
Add
dispose()method to_IndexedStackExampleState:File Modified
examples/api/lib/widgets/basic/indexed_stack.0.dartTesting
Fixes #186324