1

に複数の写真を添付し​​ようとしていますが、複数の写真を選択するためMailComposerViewControllerに使用ALAssetPickerViewControllerしています。NSMutableArray選択したアセットの参照を含む があります。取得する選択したアセットをfor loop列挙し、で初期化される を実装しています。コードは次のように記述します。arrayNSDataUIImageUIImageCGImageRef

@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]
});

私がほとんどアタッチしている各アセットは 2 MB ですが、メモリは常に減少しています。メモリを適切に解放できません。一部のメモリがリークしています。リークを見つけるのを手伝ってください。

4

1 に答える 1

-1

次のコード CGImageRelease(attachImagTemp);で添付画像を解放してみてください。nil に設定する代わりに、キャッシュ メモリを解放します。

ARC を使用していない場合は、Avi の提案に従って tempmcvc オブジェクトも解放します。

于 2013-04-23T06:08:18.030 に答える