Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leak when sending image as an attachment via Email
    primarykey
    data
    text
    <p>I have a camera application where the user can share the photos taken through email. I am using MFMailComposerViewController to send mail. Here is the piece of code.</p> <pre><code>- (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 } } </code></pre> <p>My problem is every time I send a mail through my application the VM(Virtual Memory) increases by 6/7 MB. But this does not happen if I comment out following part.</p> <pre><code> if (nil != attachmentData) { [mailViewController addAttachmentData:attachmentData mimeType:[attachmentDictionary objectForKey:@"mimeType"] fileName:[attachmentDictionary objectForKey:@"fileName"]]; } </code></pre> <p>The increased VM is due to <code>CGRasterData</code>and the responsible library is <code>CoreGraphics</code>and responsible caller is <code>CGDataProvideCreateWithCopyOfData</code>when I check it through Xcode 5.0.2 instruments.So somewhere a copy is getting created which is not getting released later.I am suspecting the memory allocated to display the image in Email <code>UIActionSheet</code>is not getting released.</p> <p>Any help is appreciated.</p> <p><strong>EDIT:</strong> Adding the piece of code where <code>attachmentData</code> is getting initialized.</p> <pre><code>- (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]; } } </code></pre> <p>Also I noticed carefully that VM increases exactly when i get the <code>UIActionSheet</code>regarding which image size to send(whether to send the original size or downscaled size). I am attaching the screenshot for the same here. <img src="https://i.stack.imgur.com/8cdnB.png" alt="UIActionSheet for selecting the image size to be sent"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload