内存通过电子邮件将图像作为附件发送时泄漏

时间:2013-12-18 04:22:16

标签: ios objective-c uiviewcontroller ios7 mfmailcomposeviewcontroller

我有一个相机应用程序,用户可以在其中分享通过电子邮件拍摄的照片。 我正在使用MFMailComposerViewController发送邮件。这是一段代码。

- (void) contactEmailRecepients:(NSArray *)emailIDs
                    subject:(NSString *)subject
                 attachment:(NSMutableDictionary *)attachmentDictionary
                     sender:(UIViewController *)sender
{   

if ([MFMailComposeViewController canSendMail])
{
    mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;

    [mailViewController setToRecipients:emailIDs];
    [mailViewController setSubject:subject];

    NSData *attachmentData = [attachmentDictionary objectForKey:@"attachmentData"];
    if (nil != attachmentData)
    {
        [mailViewController addAttachmentData:attachmentData
                                     mimeType:[attachmentDictionary objectForKey:@"mimeType"]
                                     fileName:[attachmentDictionary objectForKey:@"fileName"]];
    }

    [sender presentViewController:mailViewController
                         animated:YES
                       completion:^{}];

    attachmentData = nil;
    [attachmentDictionary removeAllObjects];
    attachmentDictionary = nil;
}
else
{
// display error message
}
}

我的问题是,每次通过我的应用程序发送邮件时,VM(虚拟内存)都会增加6/7 MB。但如果我在以下部分发表评论,就不会发生这种情况。

  if (nil != attachmentData)
    {
        [mailViewController addAttachmentData:attachmentData
                                     mimeType:[attachmentDictionary objectForKey:@"mimeType"]
                                     fileName:[attachmentDictionary objectForKey:@"fileName"]];
    }

当我通过Xcode 5.0.2工具检查时,增加的VM归因于CGRasterData且负责的库是CoreGraphics并且负责的调用者是CGDataProvideCreateWithCopyOfData。所以某个地方的副本正在获得创建后未发布。我怀疑分配给显示电子邮件UIActionSheet中的图像的内存未被释放。

感谢任何帮助。

修改 添加attachmentData初始化的代码段。

- (void)postPhotoFromPath:(NSString *)filePath
               sender:(UIViewController *)sender
{

 NSData *photoData = [NSData dataWithContentsOfFile:filePath];

if (nil == photoData)
{
 //display error message
}
else
{
    NSString *fileName = [[filePath componentsSeparatedByString:@"/"] lastObject];
    [self contactEmailRecepients:nil
                         subject:nil
                      attachment:[NSDictionary dictionaryWithObjectsAndKeys:
                                  photoData, @"attachmentData",
                                  @"image/jpeg", @"mimeType",
                                  fileName, @"fileName",
                                  nil]
                          sender:sender];
}
}

我还注意到,当我得到UIActionSheet关于要发送哪个图像尺寸(无论是发送原始尺寸还是缩小尺寸)时,VM会完全增加。我在这里附上相同的屏幕截图。 UIActionSheet for selecting the image size to be sent

0 个答案:

没有答案