tags:

views:

817

answers:

3

Hi all,

I am using the following code for UIImagePicker,

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];  
imagePicker.delegate = self;

[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];

When I run instrument, I see a memory leak on the first line of the code. Though I am releasing it, still its showing memory leak, does anyone have any idea where am I going wrong.

I installed the iPhoneCoreDataRecipes Application from iPhone Developers Sample Code help and it is having the same problem.

A: 

I think it is a bug in apple's code. when you display an image picker controller they don't seem to properly release a few small things, even if you do release the picker explicitly.

Kevlar
A: 

I have seen this myself. I think it's a problem in Apple's code, and I "solved" it by just keeping a single instance of the UIImagePickerController around, and re-using it as needed. Otherwise, my app would run out of memory after 20 or so instantiations of a UIImagePickerController.

Glenn Howes
+1  A: 

I believe Apple suggests using UIImagePicker as a singleton, meaning you only have one instance of the controller throughout the programs runtime. If you think about it, you only need one instance since the same controller can be used to pick or take pictures multiple times. UIImagePickerController seems to be memory intensive, so initializing multiple instances could lead to memory warnings, which could release other views and cause problems if you haven't taken this into account.

ius260385