Skip to content

examples: fix IndexedStack dispose memory leak#186524

Open
trippusultan wants to merge 2 commits into
flutter:masterfrom
trippusultan:master
Open

examples: fix IndexedStack dispose memory leak#186524
trippusultan wants to merge 2 commits into
flutter:masterfrom
trippusultan:master

Conversation

@trippusultan

Copy link
Copy Markdown

Problem

The IndexedStack example creates a TextEditingController but never disposes it, causing a memory leak.

Solution

Add dispose() method to _IndexedStackExampleState:

@override
void dispose() {
  fieldText.dispose();
  super.dispose();
}

File Modified

  • examples/api/lib/widgets/basic/indexed_stack.0.dart

Testing

  • Example code only — no framework changes
  • Standard Flutter example validation applies

Fixes #186324

Add missing dispose() to _IndexedStackExampleState example.
The TextEditingController was created but never disposed.

Fixes flutter#186324
@flutter-dashboard

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels May 14, 2026
@google-cla

google-cla Bot commented May 14, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +94 to +99
@override
void dispose() {
fieldText.dispose();
super.dispose();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
@override
void dispose() {
fieldText.dispose();
super.dispose();
}
@override
void dispose() {
fieldText.dispose();
super.dispose();
}
References
  1. 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)

@trippusultan

Copy link
Copy Markdown
Author

This PR fixes a memory leak in an example file (examples/api/lib/widgets/basic/indexed_stack.0.dart).

Requesting test exemption because:

  • This is example code only (not framework code)
  • Examples are validated manually by Flutter team
  • No test infrastructure exists for example snippets
  • The fix is straightforward: adding a missing dispose() method

Please review and merge. Thanks!

);
}
@override
void dispose() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@Piinks

Piinks commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Hi @trippusultan thanks for contributing! We cannot consider this change without having the CLA signed, would you please do that?

@Piinks Piinks added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 2, 2026
@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 3, 2026
@Piinks Piinks self-requested a review June 3, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexedStack example does not dispose of the TextField controller

4 participants