CF发布但仍然泄漏

时间:2013-04-26 04:45:07

标签: iphone ios core-audio

这引起了我的注意。我从iPod库中读取音频以分析音频样本,我可以做我想做的事情,缓冲区总是泄漏,我得到一个低内存警告,应用程序被杀死。 我尝试了所有建议但没有成功。下面的代码包含在静态库中,读取音频工作正常,只是缓冲区永远不会释放。我使用ARC并尝试不要拨打CFRelease,但同样的事情......感谢任何建议,我完全陷入困境!!!

- (NSInteger) getMP3Samples:(SInt16*)address{
    AudioBufferList audioBufferList;

    if (_assetReader == nil) {
        return 0;
    }

    _mp3Control.currentSampleBufferCount = 0;
    CMSampleBufferRef nextBuffer =[_assetReaderOutput copyNextSampleBuffer];

    // Is the Song ended
    if (nextBuffer == nil){
        if ([_assetReader status] == AVAssetReaderStatusCompleted) {
            [_assetReader cancelReading];
        }
        _assetReader = nil;
        _assetReaderOutput = nil;
        return _mp3Control.currentSampleBufferCount;
    }

    CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
        nextBuffer,
        NULL,
        &audioBufferList,
        sizeof(audioBufferList),
        NULL,
        NULL,
        kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment,
        &_mp3Control.blockBuffer);

    if (nextBuffer) {
        CMSampleBufferInvalidate(nextBuffer);
        CFRelease(nextBuffer);
        nextBuffer=NULL;
    }

    for (int b=0; b < audioBufferList.mNumberBuffers; b++) {
        memcpy((void *)(address+_mp3Control.currentSampleBufferCount),(void *)audioBufferList.mBuffers[b].mData,audioBufferList.mBuffers[b].mDataByteSize);
        _mp3Control.currentSampleBufferCount+=audioBufferList.mBuffers[b].mDataByteSize;
    }
    ///
    /// Return samples and not bytes!!
    ///
    return _mp3Control.currentSampleBufferCount/2;
}

1 个答案:

答案 0 :(得分:1)

你在用&amp;在{未发布的)调用代码中释放CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer返回的块缓冲区?
如果在调用&_mp3Control.blockBuffer后未释放存储在getMP3Samples:中的对象,则可能是您的内存管理问题。 (Core Foundation风格的对象不参与ARC)

你也可以通过Allocation&amp; amp;泄漏仪器以查看更多细节(我只是猜测:))。