0

I open the camera on button click and take the image in uiimage and then transfer that uiimage to other view But i receive memory warning when i do this 4-5 time.

Below is the code i worked for:-

-(void)imagePickerController:(UIImagePickerController*)picker_camera didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    [picker_camera dismissModalViewControllerAnimated:YES];
    UIImage *image=[[UIImage alloc] init];
    image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [self Methodcall:image];
    //Image_camera=image;
   // NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
    //printf("first\n");

   // [self performSelector:@selector(Methodcall) withObject:nil afterDelay:1];

    //printf("ok\n");
    //[apool release];

}
-(void)Methodcall:(UIImage *)image{
    ImageDisplayViewController *ImageDisplayViewController_obj=[[ImageDisplayViewController alloc] initWithNibName:@"ImageDisplayViewController" bundle:nil];
    ImageDisplayViewController_obj.image_FRomCamera=image;
    NSLog(@"image===>%@    camera==>%@",image,ImageDisplayViewController_obj.image_FRomCamera);
    [self.navigationController pushViewController:ImageDisplayViewController_obj animated:YES];
   // [ImageDisplayViewController_obj release];
}

-(IBAction)TakePhotoCamera:(id)sender{
    @try
    {
        UIImagePickerController *picker_camera = [[UIImagePickerController alloc] init];
        picker_camera.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker_camera.delegate = self;

        [self presentModalViewController:picker_camera animated:YES];
        [picker_camera release];
    }
    @catch (NSException *exception)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available  " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

Does any one help me out please.

Thanks in advance.

ios developer
  • 3,363
  • 3
  • 51
  • 111

1 Answers1

0

I assume you're not using ARC (is there any particular reason for this?)

  • Firstly, you are allocating an UIImage instance that's never used:

    UIImage *image=[[UIImage alloc] init];
    image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
    

    should be changed to:

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
  • Next, you are not releasing ImageDisplayViewController_obj instance here:

    // [ImageDisplayViewController_obj release];
    

    Uncomment this line.

Golden rule of memory management: Always release objects you don't need any more and don't retain anything you don't need.

I would highly recommend using ARC if you're new to Obj-C and/or memory management.

Some other suggestions:

Community
  • 1
  • 1
maroux
  • 3,764
  • 3
  • 23
  • 32
  • @MarOux thanks for the reply.I did that..still i get the crassing issue.Becuase i am using the image clicked by camera which is nearly 2MB in the application.I tries it by resizing the image into 20X20 it works..but when i try to resize it by self.frame.size..It got crash – ios developer May 03 '13 at 09:40