Memory leak on presentModalViewController

I open the camera so that the user can take a picture. I keep getting a memory leak when I took a snapshot and clicked “use”: [self presentModalViewController: imagePicker animated: YES],

Full code:

imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;      
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              (NSString *) kUTTypeMovie, nil];
imagePicker.allowsEditing = NO;

[self presentModalViewController:imagePicker animated:YES]; //This leaks

In both didFinishPickingMediaWithInfoand imagePickerControllerDidCancelI put this line:

[imagePicker dismissModalViewControllerAnimated:YES];

I know this question was asked before, but none of them saw me help me with the leak that I received.

+2
source share
4 answers

Turns out this is a bug in the iOS code.

I downloaded the Apple Developer website sample code and got the exact same leak. Therefore, I can’t fix anything, and I hope that it will be fixed soon.

0
source

If it is not ARC env:

imagePicker = [[UIImagePickerController alloc] init]; +1,

[self presentModalViewController:imagePicker animated:YES] , +2,

on [imagePicker dismissModalViewControllerAnimated:YES]; +1, , .

presentModalViewController.

+1

Try this code

imagePicker = [[[UIImagePickerController alloc] init] autorelease];

And make sure you have

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// your code

[pool release];
0
source

How about creating @propertyfor imagePickerand destination:

self.imagePicker = [[UIImagePickerController alloc] init];
0
source

All Articles