我的AVFoundation / AVCaptureSession泄漏内存在哪里?

时间:2014-09-05 19:00:56

标签: ios objective-c memory-leaks avfoundation

我正在使用AVCaptureSession来“录制”音频和视频,并使用AVAssetWriter实际记录它。当我的viewController加载时,视图显示来自摄像头的“实时馈送”,但尚未记录(存储到磁盘)。然而,记忆的使用逐渐上升,并且不会停止。我使用Instruments并试图找到泄漏,但我不确定如何解释这个。行VM:Allocation 16,00 KB不断增加,我不确定它是什么。

Leak?

我对delegate-method的实现几乎什么都不做:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:
(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);

    CFRetain(sampleBuffer);
    CFRetain(formatDescription);

    dispatch_async(movieWritingQueue, ^{

        //If recording
        if(assetWriter){
            //do stuff
        }
    });

    CFRelease(sampleBuffer);
    CFRelease(formatDescription);
}

问题是;在加载视图时(在开始记录之前),assetWriter始终为nil,因为它应该是。因此,每次调用上面的委托方法时,它都不应该真正做任何事情。 我从来没有做过太多的发布,因为ARC总是为我解决这个问题。我对CF - 事情做错了吗?

我的方法每次都以某种方式存储其中一个变量吗?

1 个答案:

答案 0 :(得分:2)

在这里回答我自己的问题:

在开发的早期阶段,我打开Enable Zombie Objects来更好地调试我遇到的奇怪异常。显然,此设置创建僵尸,或者可能阻止ARC释放某些对象或其他任何东西。通过Product->Edit Scheme->Enable Zombie Objects禁用此选项,它可以正常工作,没有泄漏。