內存泄漏所以我覺得這是一種很難的問題的正確要求,但這裏是我最好的拍攝。與聲音合成
我正在寫obj-c中的iPhone應用程序,但它涉及聲音合成,並且我在覈心音頻中使用了聲音合成程序編寫了我認爲是C(或者C++,我問了我認識的人誰使用C++,但他不認識它,但教程告訴我要將文件名更改爲.mm for C++)。出現的問題是我有大量內存泄漏,很可能是因爲我不知道如何正確調用內容。
當曾經被使用的代碼的這一部分,我得到一噸的錯誤讀取這樣的: 2011-08-23 10:18:08.769 myProgram [451:5e03] * __NSAutoreleaseNoPool():對象_NSCallStackArray類的0x171e90自動釋放,沒有池到位 - 只是泄漏
使用工具,我已經找到泄漏發生的地方,並且已經發表了一條評論來表示這一點。
這裏是所有泄漏拿出功能:
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
// Get a reference to the object that was passed with the callback
// In this case, the AudioController passed itself so
// that you can access its data.
AudioController *THIS = (AudioController*)inRefCon;
// Get a pointer to the dataBuffer of the AudioBufferList
AudioSampleType *outA = (AudioSampleType *)ioData->mBuffers[0].mData;
// Calculations to produce a 600 Hz sinewave
// A constant frequency value, you can pass in a reference vary this.
float sinSignal;
for (UInt32 i = 0; i < inNumberFrames; ++i) {
outA[i] = 0;
}
THIS->theBall = [[THIS->navDelegate ballsG] objectAtIndex:0];
THIS->amtPlaying = [[THIS->theBall playingLines] count];
//NSLog(@"%i", THIS->amtPlaying);
for (int i = 0; i < THIS->amtPlaying; i++)
{
// Loop through the callback buffer, generating samples
for (UInt32 i = 0; i < inNumberFrames; ++i) {
// calculate the next sample
sinSignal = sin( [[[THIS->theBall playingLines] objectAtIndex:i] theta] ); //leak here
sinSignal *= [[[THIS->theBall playingLines] objectAtIndex:i] volume] ;
sinSignal /= THIS->amtPlaying;
// Put the sample into the buffer
// Scale the -1 to 1 values float to
// -32767 to 32767 and then cast to an integer
outA[i] += (SInt16)(sinSignal * 32767.0f);
// calculate the phase for the next sample
[[[THIS->theBall playingLines] objectAtIndex:i] increaseTheta: [[[THIS->theBall playingLines] objectAtIndex:i] incrementer]];
}
}
return noErr;
}
如果我可以提供更多的信息,以幫助你理解我的問題,請讓我知道在評論。謝謝!
如果你正在嘗試做你處理,你需要在函數的開頭添加一個'NSAutoreleasePool *池= [[NSAutoreleasePool的alloc]初始化]'然後'[池排水]'在年底由於背景你正在使用可能的自動釋放對象。 ('ballsG','objectAtIndex:','playingLines') – Joe
這擺脫了其他的泄漏,現在的儀器顯示,我泄露NSAutoReleasePool。 – turbo
你加入'[池排水]'權之前'返回諾爾;'?另外,當你啓動一個新線程時,無論哪種方法被調用,'NSAutoreleasePool'應該是在那裏創建的第一個東西,那麼最後完成的事情應該是用同樣的方法'排除'它。 – Joe