Open CloudMountain opened 4 days ago
Hi @CloudMountain, thank you for reaching out. The Firebase Storage putBytes()
or putData()
(in Flutter) and putFile()
are asynchronous methods. It returns a Task
object that you can use to monitor the upload progress and handle its completion or failure.
Calling multiple putBytes
methods in Firebase Storage without proper management can potentially lead to Out-of-Memory (OOM) exceptions, especially on devices with limited RAM.
Are you calling the putBytes()
concurrently? If there are 50 concurrent calls with 5MB file size to upload, it's possible that the memory allocation used for this operation is more than the memory available on your device
I tried reproducing the issue and I was able to encounter the OOM exception on the 32nd concurrent call. Is there any chance you can share a bit more code snippet on how you did the “upload byte buffers of ~5MB on the order of a few hundred times during the course of a user session”? Thanks!
[REQUIRED] Step 2: Describe your environment
Firebase Component: Storage
Component version: 21.0.0 (I am using the flutter firebase_core plugin version 3.3.0 which uses firebase-bom version 33.1.0)
[REQUIRED] Step 3: Describe the problem
I originally posted about a problem I was having in the flutterfire repo here: https://github.com/firebase/flutterfire/issues/13385, and was told this was an problem with the native sdk and to raise a new issue here. Apologies in advance as I have limited experience in writing native code, and so can only really present the issue using Flutter terminology.
As can be seen in the original issue, the problem I am having is that I am trying to upload byte buffers of ~5MB on the order of a few hundred times during the course of a user session. Some users are experiencing OOM crashes of the following form:
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 2576 byte allocation with 1020864 free bytes and 996KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
After doing some memory profiling with Android Studio, I was able to narrow down the issue to calls of the
ref().putData()
and/orref().putFile()
functions from the firebase_storage flutter plugin.Steps to reproduce:
Make a button in a flutter app which simply creates a Uint8List of length 5,000,000 and then uploads it using either
putData()
orputFile()
. Recording Java/Kotlin allocations whilst tapping that button shows the following byte buffers are allocated and then never deallocated:Relevant Code: