我无法使用采样器初始化和整体化音频图形而没有内存泄漏。我试图减少我的示例中的代码量,因此以下示例甚至不启动/停止图形。所以下面的代码并没有真正做任何有用的事情,但它不应该泄漏,是吗?
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个字节,调用树看起来像这样(来自仪器中的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中。任何想法导致泄漏?我一直试图追查原因几天,这真的让我疯狂:)