我在 iPhone SDK 中的新 AVFoundation 类中遇到了奇怪的行为。
我有一个用于拍照的 AVCaptureStillImageOutput,并且我正在根据自己的喜好设置其输出设置。代码如下:
AVCaptureStillImageOutput *stillImageOutput = [[[AVCaptureStillImageOutput alloc] init] autorelease];
[stillImageOutput setOutputSettings:[NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey]];
[self setStillImageOutput:stillImageOutput];
(stillImageOutput 属性定义为“retain”)
我偶然发现了泄漏中的泄漏,100% 的泄漏故障发生在 setOutputSettings 行。我相信我仅限于所附代码中的内存管理指南,但它仍然存在泄漏。
我的解决方案是
[self.stillImageOutput setOutputSettings:nil];
在 dealloc 中,就在
之前[self setStillImageOutput:nil];
泄漏确实停止了,但看起来很奇怪。 stillImageOutput 的释放是否也应该释放其 outputSettings 属性?
无论如何,如果其他人遇到这个问题,我认为我应该分享我的解决方案。
干杯!
奥德.
最佳答案
是的,stillImageOutput 的释放应该也释放它的outputSettings 属性。要么是苹果的错误(应该让他们知道,你的用例非常简单),要么删除你的行,看看除了你的类之外是否还有其他东西卡在 stillImageOutput 对象上(它保存着 outputSettings)。
关于iphone - AVCaptureStillImageOutput 输出设置内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3437914/