[firebase_storage]: Memory management issue when calling putData()/putFile() on iOS #13532
Open
1 task done
Labels
Needs Attention
This issue needs maintainer attention.
platform: ios
Issues / PRs which are specifically for iOS.
plugin: storage
type: bug
Something isn't working
Is there an existing issue for this?
Which plugins are affected?
Storage
Which platforms are affected?
iOS
Description
The now closed issue #13385, presented an issue on both Android and iOS whereby repeatedly calling
allocates the data to be uploaded on the relevant heap and then never cleans up, which on Android was leading to an OOM error after some number of uploads (around 30-50).
A fix #13508 has been published as of firebase_storage 12.3.4 for this issue on Android, however, similar behaviour occurs on iOS. Whilst crashes seem less likely on iOS (I am assuming this is because generally iOS grants an app more RAM than Android does, as the memory footprint grows equivalently) eventually there will be a crash for someone attempting to upload a sufficiently large amount of data.
Here is a screenshot of the xcode memory profiler during which 4 buffers of 5MB each were uploaded using
putData()
using firebase_storage 12.3.4:Relevant details from the previous issue raised here:
Each call to the putData() function is allocating memory that is never freed (just to be clear in the example in the screenshot I called the upload function 4 times, waiting each time until the TaskState was TaskState.success). The stacktrace is not readable, but stepping through with the debugger I see an equivalence with Android in that the data is allocated during a call to readValueOfType(), i.e. when sending the data over from Flutter to the native side.
On iOS the situation is similar [to Android,] in the file
FLTFirebaseStoragePlugin.m
there is a_streamHandlers
Map. CallingputData()
callsreferencePutDataApp()
, which callssetupTaskListeners()
which addsFLTTaskStateChannelStreamHandler
to the _streamHandlers Map which contains a task. When creating the task the buffer to be uploaded is malloced and then never freed, and the reference to that buffer in the task in the _streamHandlers Map is never cleaned up either. Again there is acleanupWithCompletion
method which is only ever called fromdetachFromEngineOnRegistrar()
anddidReinitializeFirebaseCore()
.Reproducing the issue
Create storage tasks as follows
Each task allocates data that is never freed.
Firebase Core version
3.6.0
Flutter Version
3.22.2
Relevant Log Output
No response
Flutter dependencies
Expand
Flutter dependencies
snippetAdditional context and comments
No response
The text was updated successfully, but these errors were encountered: