Skip to content

Fix memory leak - #31

Merged
cedvdb merged 4 commits into
cedvdb:mainfrom
kosratdev:fix-memory-leak
Aug 23, 2025
Merged

Fix memory leak#31
cedvdb merged 4 commits into
cedvdb:mainfrom
kosratdev:fix-memory-leak

Conversation

@kosratdev

Copy link
Copy Markdown
Contributor

Fixes a memory leak in the CountrySelectorBase widget, where the CountrySelectorController hasn't been disposed in the dispose method. Also added leak_tracker_flutter_testing to the dev dependencies to automatically track memory leaks.

Closes #30

Checklist

  • I have bumped the version in pubspec.yaml
  • I have added an entry in changelog.md for the new pubspec version
  • (if applicable) I have added "Closes #1234" to this termplate to automatically close related issues.
  • (not required if no sensible change has been made eg: Localization) I have added tests that prove my fix is effective or that my feature works.

This change adds the leak_tracker_flutter_testing package to the dev_dependencies in pubspec.yaml and creates a new test configuration file for enabling leak detection during tests.
…orBaseState

Added a dispose method to the CountrySelectorBaseState class to ensure the controller is disposed of correctly, preventing potential memory leaks.
Add entry for version 1.0.17 to the changelog, documenting the fix for a memory leak in the CountrySelectorBase widget.
@cedvdb

cedvdb commented Aug 23, 2025

Copy link
Copy Markdown
Owner

thanks

Also added leak_tracker_flutter_testing to the dev dependencies to automatically track memory leaks.

While reading the documentation, it seems to me that the tests should use testWidgets instead testWidgetsWithLeakTracking, isn't it ? Otherwise does this do anything ?

@kosratdev

Copy link
Copy Markdown
Contributor Author

Based on this documentation, leak_tracker_flutter_testing can be enabled for all tests by enabling it in the test executable method, as we did.

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
  LeakTesting.enable();

  await testMain();
}

After that, all the testWidgets will be tracked for not disposed and not GCed objects.

@cedvdb
cedvdb merged commit 57d655b into cedvdb:main Aug 23, 2025
1 check passed
@kosratdev
kosratdev deleted the fix-memory-leak branch August 23, 2025 12:50
@kosratdev

Copy link
Copy Markdown
Contributor Author

Thanks @cedvdb for accepting the PR. Please don't forget to push it to the pub.dev.

@cedvdb

cedvdb commented Aug 24, 2025

Copy link
Copy Markdown
Owner

Thanks ! It was published on pub dev for version 1.0.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak issue

2 participants