-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[firebase_storage]: OOM native when uploading a large file when app is on relatively high memory usage #16791
Comments
Hi @SelaseKay ! import 'dart:io';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:video_player/video_player.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const TestApp());
}
class TestApp extends StatefulWidget {
const TestApp({super.key});
@override
State<TestApp> createState() => _TestAppState();
}
class _TestAppState extends State<TestApp> {
Future<void> testStorage() async {
XFile? file = await ImagePicker().pickVideo(source: ImageSource.gallery);
if (file != null) {
UploadTask task =
FirebaseStorage.instance.ref().child("test").putFile(File(file.path));
task.snapshotEvents.listen((event) {
print(event.state);
});
}
}
final List<VideoPlayerController> _controllers = [];
@override
void initState() {
for (int i = 0; i <= 7; i++) {
_controllers.add(VideoPlayerController.asset("assets/Butterfly-209.mp4"));
}
for (var c in _controllers) {
c.initialize().then((_) {
c.setLooping(true);
c.play();
c.setVolume(0);
});
}
super.initState();
}
@override
void dispose() {
for (var c in _controllers) {
c.dispose();
}
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
floatingActionButton: FloatingActionButton(onPressed: () {
testStorage();
}),
body: ListView(
scrollDirection: Axis.vertical,
children: List.generate(_controllers.length, (index) {
return SizedBox(height:100, child: VideoPlayer(_controllers[index]));
})),
),
);
}
} Steps :
Note : i am using |
Hi @tom365, thanks for reporting this and providing detailed insights. Firebase Storage attempts to upload large files in chunks to prevent memory overload. However, if there isn’t enough memory available to handle even the initial chunk, this becomes a limitation outside the scope of the plugin. To address this, I recommend structuring your app to account for available memory, perhaps by checking the memory before attempting to upload large files. That being said, I'll go ahead and close this for now. Feel free to reach out if you have anymore questions. |
Is there an existing issue for this?
Which plugins are affected?
Storage
Which platforms are affected?
Android, iOS
Description
I have previously created #16753 but the OOM was on the dart side.
However, i have managed to reproduce in my real app a crash that i have got 2 days ago in my Crashlytics dashboard.
This is the native OOM stack trace that some of my live users are experiencing currently.
Of course they have the version using the
putData
instead ofputFile
but it's not a dart OOM...-> What i believe is happening is that for example the app has 300MB RAM available for it to run. Let's say my app is consuming 250MB to run with everything inside / UI / Code etc...
That means there is a 50MB left free memory to use, but if i upload a 200MB file at this moment, it's like
firebase_storage
is reducing the 200MB by chunks to perform the upload, but the initial chunk is anyway > 50MB which cause the crash.For example in #13460 and #13385 it is probably fixed that
firebase_storage
itself handles perfectly the large files now, but i am not sure it takes in consideration the total available free memory before starting the upload, otherwise i would not have the above stack trace.Note : I have noticed it on Android because my phone has a low RAM available compared to my iPhone, but the same behavior may exist on iOS as well simply at a higher degree, but it is easier to reproduce it on Android than iOS.
Reproducing the issue
I have not managed yet to produce a sample code, but here are the steps :
I am working on the reproductible example, i save the issue to not lose it but i will update with the reproductible sample code.
Firebase Core version
3.8.0
Flutter Version
3.24.5
Relevant Log Output
Flutter dependencies
Expand
Flutter dependencies
snippetAdditional context and comments
No response
The text was updated successfully, but these errors were encountered: