Tutorial :image picker controller takes insane memory even if released



Question:

my image picker is initialized like:

self.imgPicker = [[UIImagePickerController alloc] init];

self.imgPicker.allowsEditing = YES;

self.imgPicker.delegate = self;

self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

presentation:

[self initImagePickerFromLibrary]; ----(this calls the lines I have mentioned before)

      [self presentModalViewController:self.imgPicker animated:YES];            [imgPicker release];  

apple instrument says: before calling the picker memory used is 3 Mb.While the picker is in function 12Mb.While editing image is 28Mb and my app crashes.Anyone did find a solution for this?


Solution:1

The one thing that comes to mind is that you're doing self. which may mean that your image picker is retained twice. Once, because you're allocating it and once because you're using a setter.

What does the @property line look like for imgPicker? Does it have retain? If it does, you should either change the first line in your first quote above to:

imgPicker = [[UIImagePickerController alloc] init];  

I.e. removing self..

Also in your second line, you're releasing imgPicker directly. If your @property does have retain, you should instead just do:

self.imgPicker = nil;  

The reason is that the @property synthesizing retains and releases objects when you set them. If you release the imgPicker without setting it to nil, and then, later on, try to set it to a new value, the system will attempt to release the already released object, and probably crash. The above is the same as doing:

[imgPicker release];  imgPicker = nil;  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »