Objective-c – Memory leak issue with UIImagePickerController

imageiphonememory-leaksobjective cpicker

I'm getting memory leak with UIImagePickerController class.

Here's how I'm using it:

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    [picker release];

To remove the picker i call [picker dismissModalViewControllerAnimated:YES]; in didFinishPickingImage and imagePickerControllerDidCancel.

Instruments show around 160bytes leaking as a result of this instruction:

+[UIImagePickerController _loadPhotoLibraryIfNecessary]

Apparently this issue has and is disturbing many people, and solution
to avoid this problem is to build a
singleton class dedicated for picking
images from library or capturing using
device's build in camera.

Anyone want to add something?

Best Answer

As the author of one of the first articles about the necessity to use a singleton, the motivation was to prevent a crash on the 7/8th image capture, not because of any particular worry about the leak. 160 bytes is annoying, but not a major problem, and therefore not worth worrying about (because it can't be fixed by developers).