Hi I receive memory warning whenever I am using camera.
The error is like this:
"Receive memory warning..."
And the code is:
-(void) getPhoto{
GameAppdelegate *appDelegate = (GameAppdelegate *)[[UIApplication sharedApplication]delegate];
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
///////////////////////////////////photolibrary//////////////////////////////
if([appDelegate.photoselection isEqualToString:@"User Pressed Button 1\n"])
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
if(appDelegate.sound == 1)
{
[classObj ButtonSound];
}
}
///////////////////////////////////Camera//////////////////////////////
else if([appDelegate.photoselection isEqualToString:@"User Pressed Button 2\n"])
{
@try
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
@catch (NSException * e)
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"ALERT"
message:@"Please try again"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"ok", nil];
[av show];
}
if(appDelegate.sound == 1)
{
[classObj ButtonSound];
}
}
///////////////////////////////////Cancel//////////////////////////////
else if([appDelegate.photoselection isEqualToString:@"User Pressed Button 3\n"])
{
if(appDelegate.sound == 1)
[classObj ButtonSound];
return;
}
[self presentModalViewController:picker animated:YES];
[picker release];
}
How can i handle this?please help after taking picture i crop the image and save in application like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
iRolegameAppDelegate *appDelegate = (iRolegameAppDelegate *)[[UIApplication sharedApplication]delegate];
if(appDelegate.sound == 1)
{
[classObj ButtonSound];
}
[picker dismissModalViewControllerAnimated:YES];
imageView.image = image;
CGSize size = [imageView.image size];
CGRect cropRect = CGRectMake(0.0, 0.0, size.width, size.height);
NSValue *cropRectValue = [editingInfo objectForKey:@"UIImagePickerControllerCropRect"];
cropRect = [cropRectValue CGRectValue];
appDelegate.slectedimage = image;
imageView.hidden = YES;
if( [appDelegate.Name length] != 0 && max_att == 15)
{
btnNotDone.hidden = YES;
btnDone.enabled = YES;
}
//IMAGE SAVE IN DOCUMENTS//////
[UIImagePNGRepresentation(image) writeToFile:[self findUniqueSavePath] atomically:YES];
// Show the current contents of the documents folder
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
}
Please help me. I want to remove all warnings.
You’re leaking the
UIImagePickerController. Autorelease it on creation or release it afterdismissModalViewControllerAnimated.You may still get memory warnings, photos can be enormous, especially on the iPhone 4 and at a certain point you have two of them in memory: the
UIImageand the autoreleased PNG.P.S. you don’t seem to be using
sizeandcropRectso you could delete them.