开发者

iPhone application lags after launching and dismissing MFMailComposeViewController

I have an application that uses a table view controller to display some items, after clicking on one of those items you may select to email this item. Once that happens I use the code provided by apple "MailComposer", and send the mail. However after this the scrolling in the table view is not as smooth as before.

I checked with "Leaks" and there are no leaks in my code, however there is a great deal of object allo开发者_如何学Ccation when the modal view controller for the MFMailComposeViewController, and when i dismiss my controller, all that object allocation is still there. How can i get rid of all that object allocation?. Any help will be greatly appreciated. Thank you.

-Oscar

UPDATE:

I have realized the lag only happens once you click on the To: textfield on the MFMailComposeViewController and type something, once something has been typed there will be a memory leak and the application will be sluggish. This exact same thing also happens in Apple's Mail Composer. I am using the simulator maybe this is why?. Does anyone else have a simmilar experience?

The way I am pressenting my controller is:

-(void)displayComposerSheet 
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    NSString *mailSubject = appDelegate.mailTitle;
    NSString *mailBody = appDelegate.mailLink;

    NSString *formattedString = [NSString stringWithFormat:@"<a href='%@'>%@</a>", mailBody, mailBody];

    [picker setSubject:mailSubject];

    // Set up recipients
    //NSArray *toRecipients = [NSArray arrayWithObject:@"somemail@hotmail.com"]; 
    //NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    //NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

    //[picker setToRecipients:toRecipients];
    //[picker setCcRecipients:ccRecipients];    
    //[picker setBccRecipients:bccRecipients];

    // Attach an image to the email (Warning this causes a memory leak aknowledged by Apple)
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"news_icon" ofType:@"png"];
    //NSData *myData = [NSData dataWithContentsOfFile:path];
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

    // Fill out the email body text
    [picker setMessageBody:formattedString isHTML:YES];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}

and dimissing it here:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    ....
    [self dismissModalViewControllerAnimated:YES];
}


It's a known memory leak in MFMailComposeViewController class (as of iOS 4.2 SDK). The leaks can be even seen in the MailComposer sample project by Apple. Try to run the app with Allocations instrument and notice the Overall Bytes growing up every time you click cancel and show the composer again.

See below for the similar discussion:

  1. http://discussions.apple.com/thread.jspa?threadID=2158170

  2. https://devforums.apple.com/thread/23510?tstart=15

  3. https://devforums.apple.com/message/121093#121093


Make sure you use

controller.mailComposeDelegate = self;

and not

controller.delegate = self;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜