1
找到内存泄漏并不是我的强项,但在我看来,仪器正在为NSMutableDictionary创建和设置值时指示内存泄漏。 (我正在使用ARC)。这对我来说没有任何意义,希望有人可能知道实际发生的事情。仪器指示内存泄漏对NSMutableDictionary的实例化
我有一个委托方法,它是在完成使用设备相机拍摄照片时调用的:(我为引发问题的行添加了注释)。
- (void)finishImageCaptureForBuffer:(CMSampleBufferRef)imageDataSampleBuffer withError:(NSError *)error shouldSave:(BOOL)save
{ //do some stuff...
if (save) {
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
self.imageDataSampleBuffer,
kCMAttachmentMode_ShouldPropagate);
CFMutableDictionaryRef mutableAttachments = CFDictionaryCreateMutableCopy(NULL, 0, attachments);
//MEMORY LEAK!!!!!//
NSMutableDictionary *gps = [NSMutableDictionary dictionary];
CLLocation *location = [manager location];
[gps setObject:@"" forKey:(NSString *)kCGImagePropertyGPSVersion];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss.SSSSSS"];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
//MEMORY LEAK!!!!!//
[gps setObject:ObjectOrNull([formatter stringFromDate:location.timestamp])
forKey:(NSString *)kCGImagePropertyGPSTimeStamp];
[gps setObject:(location.coordinate.latitude < 0) ? @"S" : @"N"
forKey:(NSString *)kCGImagePropertyGPSLatitudeRef];
//MEMORY LEAK!!!!!
[gps setObject:ObjectOrNull([NSNumber numberWithDouble:fabs(location.coordinate.latitude)])
forKey:(NSString *)kCGImagePropertyGPSLatitude];
[gps setObject: (location.coordinate.longitude < 0) ? @"W" : @"E"
forKey:(NSString *)kCGImagePropertyGPSLongitudeRef];
//MEMORY LEAK!!!
[gps setObject:ObjectOrNull([NSNumber numberWithDouble:fabs(location.coordinate.longitude)])
forKey:(NSString *)kCGImagePropertyGPSLongitude];
CFDictionarySetValue(mutableAttachments, kCGImagePropertyGPSDictionary, CFBridgingRetain(gps));
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:self.imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageDataToSavedPhotosAlbum:imageData
metadata:(__bridge id)mutableAttachments
completionBlock:completionBlock];
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
CFRelease(attachments);
CFRelease(mutableAttachments);
CFRelease(self.imageDataSampleBuffer);
} else { ...
凡objectOrNull检查,看看我们是否要插入的价值存在,如果没有,[NSNull空]被添加到字典中。
另一方面,运行iOS7而不是iOS8时出现此问题。
由于更换
,这也是工作时,我把它添加到,如果statment结束:CFRelease((__桥CFTypeRef)(GPS)); – jac300 2014-10-07 20:26:45