UIImagePickerControllerOriginalImage收到内存警告并崩溃

时间:2014-03-14 10:30:29

标签: ios iphone objective-c uiimagepickercontroller memory-warning

我右上角有一个UICollectionView和一个条形按钮(CameraViewController1:UICollectionViewController)。当我拍照时它会移动到一个新的视图控制器,在那里可以裁剪图像。用户有两个选项Use and Cancel after选择任何一个选项它会将图像返回到集合视图,它会像单元格一样排列。我想要拍很多照片。但是我只能在应用程序崩溃的情况下最多拍摄3张图片并显示消息&#34 ;应用程序由于内存压力而终止"但最糟糕的是,当我在运行iOS 7的iPhone 5中测试相同的应用程序时,崩溃并未发生。当我在运行iOS 7的iPhone 4中测试相同时,它得到了坠毁并产生收到的记忆警告。

这是我的代码

- (IBAction)TakeaPhoto:(id)sender {

    [[UIApplication sharedApplication]setStatusBarHidden:FALSE withAnimation:NO];

    gallery=0;
    picker1 = [[UIImagePickerController alloc] init];
    picker1.delegate = self;
    self.resizeableCropArea =YES;
    self.cropSize=CGSizeMake(300,350);
    //picker1.allowsEditing = YES;
    picker1.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker1 animated:YES completion:NULL];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [self dismissViewControllerAnimated:YES completion:NULL];

    UIImage *image =  [info objectForKey: UIImagePickerControllerOriginalImage];

    image_cap = [self imageTemp:image scaledToSize:CGSizeMake(320, 370)]; 


    dataTemp = UIImageJPEGRepresentation(image,0.0);

    CropViewController *cropController = [[CropViewController alloc] init];

    cropController.sourceImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    Original_img = UIImageJPEGRepresentation(cropController.sourceImage,0.0);

    [original_image addObject:[UIImage imageWithData:Original_img]]; //original_image Nsmutablearray

    NSLog(@"source image=%@",cropController.sourceImage);

    cropController.resizeableCropArea = self.resizeableCropArea;

    cropController.cropSize = self.cropSize;

    cropController.delegate = self;

    Cancel_Image= cropController.sourceImage;

    [self.navigationController pushViewController:cropController animated:YES];

}

1 个答案:

答案 0 :(得分:0)

@Ramanan R R,我完全赞同@ Rushabh的评论.. 你正在分配那个UIImagePickerController很多次,因为TakeaPhoto方法调用你正在分配UIImagePickerConrtoller,没有必要多次分配。它会使内存变质,这就是为什么你的应用程序将要终止或崩溃的原因。 只需在viewDidLoad中分配一次,确保再做一件事 UIImagePickerController作为一个强大的属性,因为在过去我花了整整一天来解决问题......

希望这对你有用,你的应用程序将顺利运行......:)