Skip to content

Memory Leaks - Swift 5.1 #1903

@jeremycochoy

Description

@jeremycochoy

Hello,

I open this issue because after time spent tracking memory and testing divers versions of AudioKit, it seams that the new XCode 11 Update introduced a number of memory leaks on iOS to Audiokit 4.9, 4.9.1, but also Audiokit 4.8.

I used a physical iPhone X phone for my tests.

Here is how you can reproduce what I observed:

for i in 0...3000 {
      AKMixer()
}

This simple loop should simply create and destruct object, and have no memory impact on the app. In my case, introducing this to my app increase the memory usage from 60M to 180M.
I inspected the app through the memory graph feature of XCode and here is what I see:
Capture d’écran 2019-10-22 à 20 01 42

It seams that somehow, some pointer remain set and prevent the reference counting to return to 0.

One can argue that creating 3k AKMixer is not necessary and the impact on memory should be negligible. Which is indeed true.
Unfortunately, this is note limited to AKMixer. This also apply to AKMicrophone, AKAppleSequencers... and AKSamplers.

My use case require to destruct and rebuild frequently the audio network. Therefore rebuilding AKSamplers that play the role of instruments, through AKMidiNodes. Because if this behavior, the AKSamplers stay alive, and the memory they occupy (hundreds of Mo) stay in use. The usage of the application end up being limited to 10 interactions before it get killed (Out Of Memory).
Impact on the app: Capture d’écran 2019-10-22 à 20 13 18

I manually added AudioKit 4.8 to the project and removed the pod dependency. The problem is still present and this doesn't seams an issue caused by the 4.9 or 4.9.1 updates to the code base, and the problem was still present.

This problem does not exists using XCode 10 and AudioKit 4.8. I suspect this is a consequence of the update to XCode 11 and Swift 5.1. I wouldn't be surprised apple changed the behavior of some part of Core Audio, introducing this problem to audiokit.

If I can help you to sort this problem out by providing more information, or running other test, let me know. If you have any hint to where to look at to really understand whats going on and make a workaround, let me know. For now my only fix is to downgrad to the 5.0.1 toolchain and audiokit 4.8. This doesn't seams a sustainable solution 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions