我正在尝试在 MailComposerViewController
中附加多张照片,并且我正在使用 ALAssetPickerViewController
来选择多张照片。我有一个 NSMutableArray
,其中包含所选 Assets 的引用。我正在实现一个 for 循环
,它枚举所选 Assets 的 array
以获取 UIImage
和 的
使用 NSData
>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]
});
我附加的每项 Assets 几乎都是 2 MB,但内存不断减少我无法正确释放内存;一些内存泄漏请帮助找到泄漏。
最佳答案
尝试使用以下代码释放附件图像 CGImageRelease(attachImagTemp); 以释放缓存内存而不是将其设置为 nil。
如果您还没有使用 ARC,请按照 Avi 的建议释放 tempmcvc 对象。
关于iphone - 在 MFMailComposeViewController 中附加多张照片的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16161740/