Tuesday, 27 August 2013

Memory issues with UIimagePickercontroller in iPhone

Memory issues with UIimagePickercontroller in iPhone

Got to know that solving memory leaks manually, its not as easy as how ARC
is taking care of releasing unwanted object in iOS,Thanks to Apple for
introducing ARC, which makes job easy. But i am one who stuck up with
solving memory leaks manually,as i am working on pretty old code which is
not using ARC. ok let me explain me the problem. My app contains code to
capture picture in app. here is small piece of code which is doing this
job.
- (void) takePhoto
{
ipc = [[UIImagePickerController alloc] init];
NSLog(@"retain count of IPC is %d", [ipc retainCount]);
ipc.delegate = self;
NSLog(@"retain count of IPC is %d", [ipc retainCount]);
if(ipc) {
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
NSLog(@"retain count of IPC is takephoto %d", [ipc retainCount]);
[self presentModalViewController:ipc animated:YES];
NSLog(@"retain count of IPC is %d", [ipc retainCount]);
} else {
VSCore *vsCore = [[VSCore alloc]init];
[vsCore MessageBox:@"Device does not support taking
photos"withTitle:kInfoEN];
[vsCore release]; // written on april 14th 2013
}
}
I am trying to track down the retain count of ipc object, so i had put
NSlog at certain places. once i set the delegate,(ipc.delegate = self);
delegates of UIImagePickercontroller will get called, one of them is
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{ }
after processing an image here, i am printing retain count of ipc, which
is giving me result as 5, imagepickerdelegate is incrementing retaincount
of ipc internally,but i have created the ipc object only once. according
to this link http://www.markj.net/iphone-memory-management-tutorial-video/
. number of release should be equal to retain count. if i call release
more than once i am getting message sent to deallocated instance. but
retain count of ipc is still 5. can anyone help me out on this. thanks,
i am releasing Ipc in another class, i have declared ipc as a property in
a single ton class, i am releasing ipc like this , [[[VVideoDevice
getInstance] ipc ] release]; ipc is a property in vvideodevice class.

No comments:

Post a Comment