我无法在没有内存泄漏的情况下使用采样器初始化和统一化音频图。我试图减少示例中的代码量,因此以下示例甚至不会启动/停止图表。所以下面的代码并没有真正做任何有用的事情,但它不应该泄漏,不是吗?
AudioComponentDescription cd = {};
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
AUGraph graph;
AUNode sNode;
AUNode IONode;
// Instantiate an audio processing graph
result = NewAUGraph (&graph);
//Specify the Sampler unit, to be used as the first node of the graph
cd.componentType = kAudioUnitType_MusicDevice;
cd.componentSubType = kAudioUnitSubType_Sampler;
// THESE WOULDN'T CAUSE THE LEAK!!!
// cd.componentType = kAudioUnitType_Effect;
// cd.componentSubType = kAudioUnitSubType_HighPassFilter;
// Add the Sampler unit node to the graph
result = AUGraphAddNode (graph, &cd, &sNode);
// Specify the Output unit, to be used as the second and final node of the graph
cd.componentType = kAudioUnitType_Output;
cd.componentSubType = kAudioUnitSubType_RemoteIO;
// Add the Output unit node to the graph
result = AUGraphAddNode (graph, &cd, &IONode);
// Open the graph
result = AUGraphOpen (graph);
// Connect the Sampler unit to the output unit
result = AUGraphConnectNodeInput (graph, sNode, 0, IONode, 0);
// Initialize the audio processing graph.
result = AUGraphInitialize (graph);
// Uninitialize
result = AUGraphUninitialize(graph);
CAShow(graph); // two nodes, 1 connection as expected
AUGraphClearConnections(graph);
AUGraphRemoveNode(graph, IONode);
AUGraphRemoveNode(graph, sNode);
CAShow(graph); // graph empty as expected
result = DisposeAUGraph(graph);
// -------> LEAK!
所有返回值都正常,图表按预期工作,但我找不到内存泄漏的原因。这只发生在 kAudioUnitSubType_Sampler 上,而不是音频效果。
泄漏是 48 字节,调用树如下所示(来自 Instruments 中的 Leaks-tool):
0 libsystem_c.dylib calloc
1 libobjc.A.dylib class_createInstance
2 libdispatch.dylib _os_object_alloc
3 libdispatch.dylib dispatch_semaphore_create$VARIANT$up
4 AudioToolbox AudioStreamerImpl::Initialize()
5 AudioToolbox Sampler::Initialize()
6 AudioToolbox AUBase::DoInitialize()
7 AudioToolbox _ZL18AUMethodInitializePv
8 AudioToolbox AudioUnitNodeInfo::Initialize(AudioUnitGraph*)
9 AudioToolbox AudioUnitGraph::Initialize()
10 AudioToolbox AUGraphInitialize
泄漏的对象称为“OS_dispatch_semaphore”。我正在使用 iOS 6.1,这发生在模拟器以及 iPhone 4 和 iPad 2 中。任何想法是什么导致了泄漏?几天来我一直在努力寻找原因,这真的让我抓狂:)