fix(storage, android): stream handler & event channel clean up on completion - #13508
Merged
Conversation
…aned up on completion causing out-of-memory exception
russellwheatley
marked this pull request as ready for review
October 17, 2024 13:59
SelaseKay
approved these changes
Oct 18, 2024
Lyokone
approved these changes
Oct 18, 2024
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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):

I pressed the button 10 times which creates 10 Storage tasks, here is the lastest memory footprint which has now risen to 317mb:

Finally, you can see that

eventChannelsandstreamHandlersare retaining 10 objects as anticipated: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:

Finally, looking at the size of

eventChannelsandstreamHandlers, you can see they are at 0 as we would expect with a fix: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.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?