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

[Bug] Fatal iOS 13 memory leak when using TextToSpeach.SpeekAsync #1112

Closed
@baskren

Description

@baskren

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 using TextToSpeech.SpeakAsync.

Steps to Reproduce

  1. Clone demo project and open in VisualStudio Mac Enterprise.
  2. Set the deployment target to Debug > iPad Pro (11-inch) iOS 12.2 simulator.
  3. Build, deploy, run on simulator, and terminate app.
  4. In Solution Explorer, right click on Speak_n_Leak.iOS and select Start Profiling Item
  5. Upon Xamarin Profiler launch, be sure the right platform app and device are selected and then click [Next] to go to the configuration dialog.

image

  1. In the configuration dialog, in the Common Options section, select Minimum for Level of detail and then click [Start Profiling].

image

  1. App will start.
  2. In Xamarin Profiler, note the Allocations Max value.
  3. In the app, click the [Speak n Leak : n ] button.
  4. Observer how much (or little) the Allocations Max increases with each SpeakAsync.
  5. Click [Speak n Leak : n ] again when the counter reaches 100.
  6. In Xamarin Profiler, note the Allocations Max value.
  7. In Xamarin Profiler, stop the app.
  8. Quit Xamarin Profiler (or else you're likely to end up running the above app in the iOS 12.2 simulator again).
  9. In VisualStudio Mac, switch the deployment target to Debug > iPad Pro (11-inch) iOS 13.1 (or higher).
  10. Repeat steps 3 - 13 again.

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):

  1. Return to VisualStudio Mac, go to the menu bar, click on the ** Tools / (iOS and Mac) Instruments** to start Instruments application.
  2. In Instruments, in the Choose a profiling template for dialog, select the iPad Pro (11-inch) (13.1) > Speak_n_Leak target, verify that Allocations is selected, and click [Choose].
  3. Click the start button (top left in Instruments) to start profiling.
  4. Click the [Speak n Leak : 0] button and click it again (to stop) when it says [Speak n Leak: 10].
  5. Select the time span between the start and stop of the speaking.

Expected Behavior

  • When profiling the app on a iOS 12 device (steps 3-10), the result of step 8 is 189.5MB:

image

  • And step 12 is 198.3MB :

image

  • 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

  • When profiling the app on a iOS 13 device (steps 3-10), the result of step 8 is 142.4MB:

image

  • And step 12 is 299.8MB :

image

  • The change is 157.4MB (1.57MB per SpeakAsync)

  • The result of Instruments profiling, before step 20 is 30.03MB:

image

  • And after step 21 is 274.26MB:

Screen Shot 2020-02-21 at 12 22 44 PM

**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!
image

  • In our production app, on actual devices, this leak leads to the following fatal crash. This is because, if leaked to 1.4GB, iOS kernel will kill the app:
default	07:04:06.960949-0500	kernel	68888.699 memorystatus: killing_specific_process pid 822 [TMCS.iOS] (per-process-limit 10) 1484807KB - memorystatus_available_pages: 14750
default	07:04:07.231722-0500	ReportCrash	starting prolongation transaction timer
default	07:04:07.231765-0500	ReportCrash	Attempting to write jetsam report
default	07:04:07.231815-0500	ReportCrash	Process TMCS.iOS [822] killed by jetsam reason per-process-limit

Basic Information

  • Version with issue: all
  • Last known good version: none
  • IDE: VisualStudio Enterprise Mac Enterprise 8.4.5 (build 19)
  • Platform Target Frameworks:
    • iOS: info.plist Deployment Target from 8.0 to 13.0
  • Nuget Packages: Xamarin.Forms 4.3.0.908675
  • Affected Devices: all iOS 13 devices

Screenshots

See above

Reproduction Link

https://github.com/baskren/Speak_n_Leak

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions