内存泄漏在MFMailComposerViewController中附加多张照片

时间:2013-04-23 05:37:16

标签: iphone ios multithreading cgimage alasset

我正在尝试在MailComposerViewController附加多张照片,而我正在使用ALAssetPickerViewController来挑选多张照片。我有一个NSMutableArray,其中包含所选资产的参考。我正在实施一个for loop,该array枚举NSData个所选资产,以获得UIImage UIImageCGImageRef初始化为@autoreleasepool { NSString *emailTitle = @"Test"; NSString *messageBody = @"IOS programming is so fun!"; NSArray *toRecipents = [NSArray arrayWithObjects:@"abc@gmail.com", nil]; MFMailComposeViewController *tempmcvc = nil; tempmcvc = [[MFMailComposeViewController alloc] init]; tempmcvc.mailComposeDelegate = self; [tempmcvc setSubject:emailTitle]; [tempmcvc setMessageBody:messageBody isHTML:YES]; [tempmcvc setToRecipients:toRecipents]; tempmcvc.modalPresentationStyle=UIModalPresentationFullScreen; tempmcvc.navigationBar.barStyle = UIBarStyleBlackOpaque; for (AlAsset *assets in SelectedAssetsarray) { @autoreleasepool { UIImage *attachImagTemp = nil; NSData *myData = nil; CGImageRef iref = [assets.defaultRepresentation fullScreenImage]; NSString *nameOfImgTemp; attachImagTemp = [UIImage imageWithCGImage:iref]; nameOfImgTemp = assets2.defaultRepresentation.filename; myData = UIImageJPEGRepresentation (attachImagTemp, 1.0); [tempmcvc addAttachmentData:myData mimeType:@"image/jpeg" fileName:nameOfImgTemp]; myData = nil; attachImagTemp = nil; iref = nil; nameOfImgTemp = nil; ALAsset *_temp = assets2; _temp = nil; } } } dispatch_async(dispatch_get_main_queue(), ^(void) { [self presentModalViewController:tempmcvc animated:YES] }); 。 代码如下:

{{1}}

我附加的每个资产都不是2 MB,但是内存不断减少我无法正常释放内存;一些记忆泄漏请帮助找到泄漏。

1 个答案:

答案 0 :(得分:-1)

尝试使用以下代码 CGImageRelease(attachImagTemp); 发布附件图像,以释放缓存而不是将其设置为nil。

如果您没有使用过ARC,也可以按照Avi的建议释放tempmcvc对象。

相关问题