Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Fix to fatal iOS 13 memory leak when using TextToSpeach.SpeekAsync #1112 #1153

Merged
merged 3 commits into from
Mar 25, 2020

Conversation

baskren
Copy link
Contributor

@baskren baskren commented Mar 6, 2020

Description of Change

In TextToSpeech.ios.tvos.watchos.cs:

  • Went from one instance of AVSpeechSynthesizer being instantiated per TextToSpeach.SpeakAsync call to a single static lazy instance of AVSpeechSynthesizer.
  • Instantiated the (per TextToSpeach.SpeakAsync call) instance of AVSpeechUtterance in a using statement, to implicitly invoke a dispose() upon it.

TESTS

To test, use the TextToSpeach sample in the existing Xamarin.Essentials.Sample.iOS app with Xamarin.Profiler or Instruments. If there is a way to automate this, I'm all ears.

SAMPLES

The TextToSpeach sample in the existing Xamarin.Essentials.Sample.iOS app is capable of demonstrating this issue. However, the demo project in issue #1112 is more concise.

UPDATED DOCUMENTATION

Nothing public was effected by this change.

Bugs Fixed

API Changes

none

Behavioral Changes

none

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Updated documentation (see walkthrough)

Redth and others added 2 commits March 3, 2020 17:58
* Implement vertical accuracy in GeoLocation API (xamarin#1103)

* Location: add property 'VerticalAccuracy' (xamarin#1099)

* vertical accuracy is only available in Android API level 26 and above (xamarin#1099)

* update Samples app to show vertical accuracy on GeolocationPage

* add missing documentation bits for Location.VerticalAccuracy

* .gitattributes: get better diff context for C# code (xamarin#1115)

* Location.VerticalAccuracy: add runtime check for Android version (xamarin#1099) (xamarin#1116)

* the compile-time check is not enough
* it crashed on old Android versions (<8.0)

* xamarinGH-1102 Fix launcher on older devices (xamarin#1120)

* Update Launcher.ios.tvos.cs

* OpenUrlAsync was introduced in iOS 10 not 12

https://docs.microsoft.com/en-us/dotnet/api/uikit.uiapplication.openurlasync?view=xamarin-ios-sdk-12

* Fix trailing whitespace

* Really? fix whitespace

* Really! Fix whitespace

* Fixes xamarin#1129 - set empty required declarations on UWP (xamarin#1133)

* Fixes xamarin#1129 - set empty required declarations on UWP

* Update Permissions.uwp.cs

* Update Xamarin.Essentials.csproj (xamarin#1136)

* xamarinGH-1142 AccessBackgroundLocation only when compile & running Q (xamarin#1143)

* AccessBackgroundLocation only when compile & running Q

* put if compile check around permission

* xamarinGH-1121 If VC is null use TraitCollection (xamarin#1144)

* Fixes xamarin#1123 (xamarin#1126)

* Update PlacemarkExtensions.xml (xamarin#1132)

Co-authored-by: Janus Weil <janus@gcc.gnu.org>
Co-authored-by: James Montemagno <james.montemagno@gmail.com>
Co-authored-by: Michael <Michael@ZPF.fr>
@msftclas
Copy link

msftclas commented Mar 6, 2020

CLA assistant check
All CLA requirements met.

@jamesmontemagno
Copy link
Collaborator

@praeclarum are you able to look at this PR? You have a lot of experience with AVSpeechSynth.

I remember that in my plugin we moved to creating a new one because if routes changed then it would get messed up: jamesmontemagno/TextToSpeechPlugin#59

@baskren
Copy link
Contributor Author

baskren commented Mar 6, 2020

@jamesmontemagno You are likely right ... this is just the kind of thing I suspected could be of concern. My feelings won't be hurt if someone else has a way to fix issue #1112 and prevent jamesmontemagno/TextToSpeechPlugin#59. I am guessing @nexxuno was on the right track with jamesmontemagno/TextToSpeechPlugin@77ab3e9.

@praeclarum
Copy link

I have always used a singleton synthesizer object. I wonder if that bug that got filed and your PR was just because of a transient iOS bug or maybe the audio session was misconfigured. This change seems right to me.

There are other changes outside the scope of the synthesizer, do you want me to review those?

@jamesmontemagno
Copy link
Collaborator

@praeclarum nope, just the synthesizer one. Would be good to just test the audio route change. perhaps it was an iOS thing back in the day and no longer an issue.

@baskren
Copy link
Contributor Author

baskren commented Mar 6, 2020

@jamesmontemagno & @praeclarum

What would a change-of-audio-route test look like? Start with using device speakers and then switch to Bluetooth speakers?

@praeclarum
Copy link

@baskren Yep that would be a change. Also settings changes can cause it, backgrounding, switching audio session configuration (global properties in AVFoundation), phase of moon...

Apple makes no mention of needing to handle it in their docs though.

@baskren
Copy link
Contributor Author

baskren commented Mar 6, 2020

@praeclarum

I'll be able to test this on Monday.

@nexxuno
Copy link

nexxuno commented Mar 7, 2020

@baskren: yes I had problem with backgrounding and route changes for example.

(ps. At a glance I'm seeing a possible bug in semaphore handling when looking at my commit cited above)

@baskren
Copy link
Contributor Author

baskren commented Mar 9, 2020

@jamesmontemagno, @praeclarum, @nexxuno

I've successfully tested the commit on production devices running iOS 13.3.1 (iPad Air 2) and 12.4 (iPad 6th gen).

@jamesmontemagno jamesmontemagno added this to the 1.5.2 milestone Mar 9, 2020
@jamesmontemagno
Copy link
Collaborator

@nexxuno can you describe and point out the code more?

@nexxuno
Copy link

nexxuno commented Mar 9, 2020

@nexxuno can you describe and point out the code more?

Hello, do you need a comment about my old commits or something else?

I remember that my first fix involved recreating the synth object each time the route changed (while disposing the old one) but then you suggested to create a new one each time SpeechUtterance was called and then disposing it at the end of it's usage. But I don't know if it's relevant anymore 2 years later...

Everything about that fix was about a functional bug (audio problems when switching to background processing) while this looks about memory issues.

@jamesmontemagno
Copy link
Collaborator

Thanks @nexxuno yeah, just wanted to make sure we checked to make sure we didn't regress at all from what yours fixed.

@jamesmontemagno jamesmontemagno added the awaiting-review This PR needs to have a set of eyes on it label Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting-review This PR needs to have a set of eyes on it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants