我正在使用 AVCaptureSession
来“录制”音频和视频,并使用 AVAssetWriter
来实际录制它。当我的 viewController 加载时, View 显示来自相机的“实时馈送”,但尚未录制(存储到磁盘)。然而,内存使用逐渐上升,并且不会停止。我使用 Instruments
并试图找到泄漏点,但我不确定如何解释这一点。 VM:Allocation 16,00 KB
行不断增加,我不确定它是什么。
此时我对委托(delegate)方法的实现几乎什么都不做:
- (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);
}
问题是;加载 View 时(在开始记录之前),assetWriter 始终为 nil,这是应该的。所以每次调用上面的委托(delegate)方法时,它实际上不应该做任何事情。
我从来没有做过太多的发布,因为 ARC 总是为我解决这个问题。我对 CF
做错了什么吗?
我的方法是否每次都以某种方式存储这些变量之一?
最佳答案
在这里回答我自己的问题:
在开发的早期,我打开了 Enable Zombie Objects
以更好地调试我遇到的一个奇怪的异常。显然,此设置创建僵尸,或者可能阻止 ARC 释放某些对象或其他任何东西。通过 Product->Edit Scheme->Enable Zombie Objects
禁用此选项,它按预期工作,没有泄漏。
关于ios - 我的 AVFoundation/AVCaptureSession 泄漏内存在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25692320/