AUv3 -- deinit / dealloc never called

Hi,

I am designing an AUv3 plugin for Logic / Garageband. I heavily relied upon the AUv3Filter demo supplied by Apple due to lack of documentation on building AUv3 plugins. However, I noticed a problem both in my plugin and Apple's AUv3Filter demo plugin.

When I add a deinit function to Apple's AUv3FilterDemo.swift class, it never gets called. Not when the plugin is removed from a Logic project, not when Logic exits, never.

My plugin, unsurprisingly, has the same problem (dealloc / Objective-C). It's pretty serious however, because my plugin is a wrapper for a C++ class that has a lot of stuff going on and needs to be deconstructed when it finishes running.

I spent a few hours with Apple's demo trying to track down any strong references that might persist after the plugin exits, but nothing I did seemed to make any difference.

Anybody else have this issue?

My Objective-C function deallocateRenderResources() gets called. My deinit{} function in Swift does not. Have you figured out a solution in the meantime?

I noticed this as well. I think this is due to a circular reference between the audio unit and the AudioUnitBusArray instances which hold a reference to the audio unit. I changed my code to always return a new instance of AudioUnitBusArray:

override public var inputBusses: AUAudioUnitBusArray { .init(audioUnit: self, busType: .input, busses: [inputBus]) }
override public var outputtBusses: AUAudioUnitBusArray { .init(audioUnit: self, busType: .output, busses: [outputBus]) }

Also, make sure you use [weak self] for your parameter tree blocks, and any other similar blocks:

parameters.parameterTree.implementorValueProvider = { [weak self] param in
  self?.kernel.get(param) ?? AUValue(0)
}
parameters.parameterTree.implementorValueObserver = { [weak self] param, value in
  self?.kernel.set(param, value: value)
}

I have test cases that make sure I get an AUValue(0) from the parameter tree after nulling out a reference to my audio unit.

thanks for sharing. I don't know how to apply that in Objective-C world but it looks interesting.It turned out that in my case deinit() wasn't called because of retain cycles in Swift, which were actually quite easy to fix.

AUv3 -- deinit / dealloc never called
 
 
Q