【发布时间】:2013-08-20 07:17:21
【问题描述】:
我在[self setImageData:[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]]; 观察到 25MB 的内存爆发
下面的代码 sn-p 正在捕获图片并提供 jpg 格式的数据。当我们拍摄更多照片时,系统会报告内存不足警告。
在分析器中我们看不到泄漏,但有时应用程序会报告内存不足警告,即使在 20MB 和应用程序崩溃。
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
[[self captureSession] stopRunning];
if (imageSampleBuffer != NULL)
{
CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments)
{
NSLog(@"attachements: %@", exifAttachments);
}
[self setImageData:[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]];
}
imageSampleBuffer = nil;
// call the designated delegate
[self.aCDMCameraCaptureNotificationDelegate imageDidSuccessfullyCaptured];
}];
【问题讨论】:
-
除非您降低所捕获图片的分辨率,否则您将无法减少这部分代码使用的内存量。您必须让您的应用准备好处理内存不足警告而不会崩溃。
-
分析后,我看到以下内存泄漏。
标签: iphone memory-management avcapturesession