[BUG]:
Flutter Sound Version :
FULL or LITE flavor ? FULL •Important: Result of the command : flutter pub deps | grep flutter_sound
|-- flutter_sound 9.28.0
|-- flutter_sound_platform_interface...
|-- flutter_sound_web...
Severity
- Crash ? es, the application crashes due to a fatal OutOfMemoryError.
Platforms you faced the error
•iOS ? No (not tested for this specific issue) •Android ? Yes •Flutter Web ? No •Emulator ? Not tested •Real device ? Yes
Describe the bug The application crashes with a fatal java.lang.OutOfMemoryError on Android when the FlutterSoundRecorder is used for continuous, long-term audio stream monitoring. The crash occurs after the app has been running in this monitoring state for several hours (e.g., 2-3+ hours).The issue seems to be a native memory leak within the Android FlautoRecorderEngine, as memory usage gradually increases over time until the OS can no longer allocate memory for the audio buffer, leading to a crash To Reproduce The bug is related to long-term resource management rather than a specific user interaction. The steps to reproduce the scenario are:1.Initialize FlutterSoundRecorder with logLevel: Level.debug.2.Call await myRecorder.openRecorder().3.Call await myRecorder.startRecorder(toStream: ...) to begin a continuous audio stream from the microphone. The primary goal is to listen to the onProgress stream for decibel levels, not necessarily to write the audio data to a file.4.Let the application run in this monitoring state for an extended period (several hours).5.The application will eventually crash
Logs!!!!
(This is very important. Most of the time we cannot do anything if we do not have information on your bug).
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 8208 byte allocation with 1710048 free bytes and 1669KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
at java.nio.HeapByteBuffer.
@BoshiLee , Thank you for your Problem Report which is clear and complete. (I like Problem Reports like that 👍 ).
Your problem is probably because the Audio Data are stacked into your Dart stream but you never consume them.
Do something like that :
recordingDataControllerUint8 = StreamController<Uint8List>();
// You must listen to your stream to consume the audio data
recordingDataControllerUint8.stream.listen((Uint8List buf) {
// **** Here you can ignore the `buf` audio data if you don't care of them. ****
});
await _mRecorder.startRecorder(
codec: Codec.pcm16,
sampleRate: 48000,
numChannels: 1,
audioSource: AudioSource.defaultSource,
toStream: recordingDataControllerUint8.sink,
);
Don't forget to close your controller when you are done with your record :
await _mRecorder.stopRecorder();
recordingDataControllerUint8.close();