Quote:
Originally Posted by simsimma
I think so, here is the code:
Code:
-(BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject
{
if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
|| (delegateObject == nil) || (controller == nil))
return NO;
if(imagepicker == nil){
imagepicker = [[UIImagePickerController alloc] init];
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagepicker.delegate = delegateObject;
}
//picker.allowsImageEditing = YES;
// Picker is displayed asynchronously.
[controller presentModalViewController:imagepicker animated:YES];
return YES;
}
imagepicker is deallocated in the dealloc function of my parent view controller.
Now, after a person takes a photo I do the following:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
//we need to save each image and then show it in the interface!
int row = (self.numPhotos / 4);
int mod = self.numPhotos % 4;
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setFrame:CGRectMake(mod * 80.0, row*120.0 + 120.0, 80.0, 120.0)];
[self.view addSubview:imageview];
[imageview release];
self.numPhotos = self.numPhotos + 1;
[self.navigationController dismissModalViewControllerAnimated:YES];
}
From running instruments I see that after I take the image, 8MB or so of space is taken up. But that space never gets released. So each time I take a photo, the memory goes up to hit 40MB which then causes the crash.
What am I doing wrong here? How do I clear the data taken by the UIImagePickerController class so that I'm not causing a crash after 5 pictures?
Cheers
|
I must be missing something.
For every photo (1600x1200 at RGBA, so 8MB), you create a UIImageView which displays the image, of course the memory usage increases by 8MB. About 4 of those full size images will make iPhone run out of memory and crash.
The problem (at least in the above code) is not the image picker, it is your code.