-
Notifications
You must be signed in to change notification settings - Fork 505
[Bug] Fatal iOS 13 memory leak when using TextToSpeach.SpeekAsync #1112
Comments
I investigated this, we just need a using block around the AVSpeechUtterance. This means we need to eagerly await our Speak function to have the using dispose correctly. |
I actually tried this as well but it didn’t work for me - which my mean I didn’t do it right. I’ll try to share my source when I can get to my laptop.
…Sent from my iPhone
On Feb 24, 2020, at 6:12 AM, Niklas Schilli ***@***.***> wrote:
I investigated this, we just need a using block around the AVSpeechUtterance. This means we need to eagerly await our Speak function to have the using dispose correctly.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
We also need to dispose the SpeechSynthesizer, just adding that to the finally block should do the trick. |
In the hope of you showing me where I'm doing it wrong, I have added the use-using branch to the demo repo. It also leaks profusely. A few things noteworthy:
Any insights you may have would be greatly appreciated! |
If you tested said code in Debug mode it will never collect the objects as they are still live in Debug configurations. That is just a peculiarity to improve debug experience, all variables in the local call frame will be kept alive until the block is exited. |
@Mrnikbobjeff, thank you for being willing to engage me on this. Greatly appreciated!
Sounds reasonable ... unfortunately I cannot get Xamarin.Profiler to start profiling a release build of this small app. When I try to start the app, Xamarin.Profiler is stuck on "Starting application ...". When I stop profiling, Xamarin.Profiler presents the message:
Maybe I'm missing something ... there doesn't appear to be a
|
Just tried profiling the demo app, in a release build, in Instruments. The good news: Unlike Xamarin.Profiler, Instruments was able to profile the app. The bad news: It still leaks. |
Well the easy fix for us would be to cache the AvSpeechSynthesizer and see if this solves the leak. I had another Idea I would like to test if it still leaks if you actually set a valid voice. Currently it is only set if there is an options object being passed. Perhaps then it does not have to do whatever it does. You actually also did not identify the object being allocated, if you check the column it reads resposible library |
Caching AVSpeechSynthesizer works! For our application, this appears to be an acceptable short term solution in that we already have a queue in place upstream - which should prevent multiple concurrent subscribers to
Not sure I'm following you here and I would like to be sure I understand. Could you be referring to Xamarin.Profiler or Instruments? Can you elaborate? |
FWIW:
|
@baskren been following the thread and thanks for looking into this. Do you want to send a PR down for review? |
@baskren In your initial issue post you wrote
If you check the last image you posted (which is the only time that string is ever visible), you can see that the column header reads "responsible library". You assumed that the name of the Objekt being leaked is displayed there, but that is just the offending library. |
Fix to fatal iOS 13 memory leak when using TextToSpeach.SpeekAsync #1112
Fixed in #1153 thanks! |
Description
TextToSpeech.SpeakAsync
leaks significant memory when used with iOS 13. If repeated enough times, this will trigger the iOS kernel to terminate the app usingTextToSpeech.SpeakAsync
.Steps to Reproduce
Optional: Repeat all of the above using actual iOS device. Get similar results.
Optional: Try the following (I could not get this to work on the iOS 12 build of the app):
Expected Behavior
The change is 8.8MB (0.088MB per SpeakAsync)
When profiling using Instruments, expect the app to not create a bunch of live objects during speaking.
Actual Behavior
The change is 157.4MB (1.57MB per SpeakAsync)
The result of Instruments profiling, before step 20 is 30.03MB:
**Notice the following: **
- The change in Persistent memory: 244.23MB (2.44 MB per SpeakAsync)!
- The large number of live
TextToSpeachBundleSupport
objects at +500KB each!Basic Information
Screenshots
See above
Reproduction Link
https://github.com/baskren/Speak_n_Leak
The text was updated successfully, but these errors were encountered: