Skip to content

fix(storage, android): stream handler & event channel clean up on completion - #13508

Merged
russellwheatley merged 2 commits into
mainfrom
storage-13385
Oct 18, 2024
Merged

fix(storage, android): stream handler & event channel clean up on completion#13508
russellwheatley merged 2 commits into
mainfrom
storage-13385

Conversation

@russellwheatley

@russellwheatley russellwheatley commented Oct 16, 2024

Copy link
Copy Markdown
Member

Description

The stream handler and event channel were never cleaned up once the StorageTask had finished, causing memory leak and ultimately an out-of-memory exception.

Test Setup

Using the following setup, I continued to create Storage Tasks.

ElevatedButton(
  onPressed: () async {
  Uint8List buffer = Uint8List(5000000);
  Reference ref =  FirebaseStorage.instance.ref();
  await ref.child('flutter-tests/putdata').putData(buffer);
},
child: const Text('Storage test'),
),

Profiling App before fix

I profiled the app to see the memory footprint.

Here is the baseline memory footprint starting the app, it starts with 269.1mb ( to the right of image, half way up):
Screenshot 2024-10-16 at 17 27 37

I pressed the button 10 times which creates 10 Storage tasks, here is the lastest memory footprint which has now risen to 317mb:
Screenshot 2024-10-16 at 17 28 56

Finally, you can see that eventChannels and streamHandlers are retaining 10 objects as anticipated:
Screenshot 2024-10-16 at 17 29 46

Profiling App after fix

Profiled the app after pressing the button at least 10 times you can see that the memory remains similar to the baseline memory measured earlier:
Screenshot 2024-10-16 at 17 24 48

Finally, looking at the size of eventChannels and streamHandlers, you can see they are at 0 as we would expect with a fix:
Screenshot 2024-10-16 at 17 25 49

Related Issues

closes #13385
closes #13460

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@russellwheatley
russellwheatley merged commit f010b46 into main Oct 18, 2024
@russellwheatley
russellwheatley deleted the storage-13385 branch October 18, 2024 09:23
@firebase firebase locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

3 participants