【问题标题】:MFMailComposeViewController memory managementMFMailComposeViewController 内存管理
【发布时间】:2015-01-23 14:59:26
【问题描述】:

我创建了一个应用程序,用户使用前置摄像头拍照并通过电子邮件发送,该应用程序至少 8 小时不会进入后台;该应用程序显示在办公室中,并且必须始终位于前台。一切都发生在 UIViewController 中。

问题在于 MFMailComposeViewController,特别是它消耗的内存。在 Instruments - Activity Monitor 中有一个 MailCompositionS,它在实际内存使用中不断增加。

我的代码是:

- (void)emailPhoto
{
    NSString *emailTitle;
    NSString *messageBody;

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:NO];

    NSData *dataImage = UIImageJPEGRepresentation(photoView.image, 0.4);
    [mc addAttachmentData:dataImage mimeType:@"image/jpeg" fileName:@"image.jpg"];

    [self presentViewController:mc animated:YES completion:nil];

    mc = nil;
    dataImage = nil;
}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [self dismissViewControllerAnimated:YES completion:^{

        [self backToCamera];
    }];
}

我真的不明白可能是什么问题。无论有没有图像附件,MailCompositionS 的内存消耗都会不断增加,并且由于应用程序始终停留在 UIViewController 中并且永远不会进入后台,因此永远不会释放内存。

PS 我没有发现任何泄漏。

【问题讨论】:

    标签: ios memory-management mfmailcomposeviewcontroller mfmailcomposer


    【解决方案1】:

    我认为您必须在属性中创建一次 MFMailComposeViewController 实例。而不是为每张照片创建一个实例。只需复制几行。 self.mc = [[MFMailComposeViewController alloc] init]; mc.mailComposeDelegate = self;viewDidLoad()viewWillAppear()

    祝你好运

    【讨论】:

    • 我需要多次使用 MFMailComposeViewController,如果我在 viewDidLoad 中分配 init 第二次我需要发送电子邮件将不起作用。
    猜你喜欢
    • 1970-01-01
    • 2011-07-21
    • 2012-03-21
    • 1970-01-01
    • 2016-10-12
    • 2012-06-14
    相关资源
    最近更新 更多