flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

Android 15 - Crash - OutOfMemory

Open MapleNoise opened this issue 5 months ago • 0 comments

🐛 Bug Report

I've noticed a significant number of TTS crashes on Android devices thanks to Crashlytics. Specifically on Android 15 on my published version, I can't reproduce it in debug :

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 528 byte allocation with 1658864 free bytes and 1619KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
       at java.io.ObjectInputStream$BlockDataInputStream.<init>(ObjectInputStream.java:2753)
       at java.io.ObjectInputStream.<init>(ObjectInputStream.java:350)
       at android.os.Parcel$2.<init>(Parcel.java:5369)
       at android.os.Parcel.readSerializableInternal(Parcel.java:5369)
       at android.os.Parcel.readSerializable(Parcel.java:5337)
       at android.speech.tts.Voice.<init>(Voice.java:87)
       at android.speech.tts.Voice.<init>()
       at android.speech.tts.Voice$1.createFromParcel(Voice.java:113)
       at android.speech.tts.Voice$1.createFromParcel(Voice.java:110)
       at android.os.Parcel.readTypedObject(Parcel.java:4232)
       at android.os.Parcel.createTypedArrayList(Parcel.java:3872)
       at android.speech.tts.ITextToSpeechService$Stub$Proxy.getVoices(ITextToSpeechService.java:919)
       at android.speech.tts.TextToSpeech.getVoice(TextToSpeech.java:1798)
       at android.speech.tts.TextToSpeech.lambda$setLanguage$9(TextToSpeech.java:1626)
       at android.speech.tts.TextToSpeech.$r8$lambda$amUMl1sMCV65T89ROegv6XNskBw()
       at android.speech.tts.TextToSpeech$$ExternalSyntheticLambda8.run(D8$$SyntheticClass)
       at android.speech.tts.TextToSpeech$Connection.runAction(TextToSpeech.java:2405)
       at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:857)
       at android.speech.tts.TextToSpeech.runAction(TextToSpeech.java:847)
       at android.speech.tts.TextToSpeech.setLanguage(TextToSpeech.java:1580)
       at com.tundralabs.fluttertts.FlutterTtsPlugin.onInitListenerWithoutCallback$lambda$5(FlutterTtsPlugin.kt:264)
       at android.speech.tts.TextToSpeech.lambda$dispatchOnInit$0(TextToSpeech.java:934)
       at android.speech.tts.TextToSpeech.$r8$lambda$y-uaMPlobiYouiY_T7xFoJSwPww()
       at android.speech.tts.TextToSpeech$$ExternalSyntheticLambda13.run(D8$$SyntheticClass)
       at android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:943)
       at android.speech.tts.TextToSpeech.-$$Nest$mdispatchOnInit()
       at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2324)
       at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2284)
       at android.os.AsyncTask.finish(AsyncTask.java:771)
       at android.os.AsyncTask.-$$Nest$mfinish()
       at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loopOnce(Looper.java:249)
       at android.os.Looper.loop(Looper.java:337)
       at android.app.ActivityThread.main(ActivityThread.java:9604)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:615)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Image

In theory, this happens when the TTS is initialised and Android loads all the voices. And since the change in page loading from 4kb to 16kb since Android 15, this can lead to memory leaks : https://developer.android.com/guide/practices/page-sizes?hl=fr#:~:text=%C3%80%20partir%20d'Android%2015,ces%20appareils%20de%2016%20Ko.

Configuration

[✓] Flutter (Channel stable, 3.32.4, on macOS 15.4.1 24E263 darwin-arm64, locale fr-FR) [552ms] • Flutter version 3.32.4 on channel stable at /flutter_sdk_latest • Upstream repository https://github.com/flutter/flutter.git • Framework revision 6fba2447e9 (5 weeks ago), 2025-06-12 19:03:56 -0700 • Engine revision 8cd19e509d • Dart version 3.8.1 • DevTools version 2.45.1

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [5,0s] • Android SDK at /Users/lionel.malloggi/Library/Android/sdk • Platform android-36, build-tools 35.0.1 • Java binary at: /Applications/Android Studio 2.app/Contents/jbr/Contents/Home/bin/java This is the JDK bundled with the latest Android Studio installation on this machine. To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk". • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11) • All Android licenses accepted.

Version: flutter_tts: 4.2.3

Platform:

  • [X] :robot: Android

Thanks for you help 🙏

MapleNoise avatar Jul 15 '25 15:07 MapleNoise