memory-leaksavaudioenginexcode-instruments

Accessing some of AVAudioEngine properties or methods causing a memory leak in Xcode Instruments


I'm not sure wether AVAudioEngine is internally causing some memory leaks or it is a bug of Xcode Instruments but I had a strange case where I was seeing memory leaks after launching the app.

Finally reduced the code to just calling let node = AVAudioEngine().inputNode in AppDelegate. Notice I'm even initialising it in place and accessing the input node. It should be created and deallocated immediately after didFinishLaunching scope ends. When I run instruments I keep getting this memory leak for some reason.Leak in XCode Instruments

It's really easy to reproduce just by writing this for example and running Xcode Instruments leak preset.

func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    let node = AVAudioEngine().inputNode
    return true
}

Solution

  • Apple support has contacted me and it appeared to be an expected behavior.

    UISoundNewDevice is a global object that is not expected to be deallocated (as the function name suggests: immortal). Thus, this is a false alarm.