Ios 使用UIImagePickerController时出现内存警告

Ios 使用UIImagePickerController时出现内存警告,ios,memory,uiimagepickercontroller,memory-warning,Ios,Memory,Uiimagepickercontroller,Memory Warning,当我在iPhone上使用相机时,会收到内存警告。我也使用弧 当您拍摄照片并按下相机视图控制器上的“使用照片”按钮时,我会收到一条内存警告。其目的是一旦按下“使用照片”按钮,它就会更改ImageView的内容 我认为内存问题可能是因为捕获的图像是全屏的,而ImageView是250h 250w。但我尝试缩小相机拍摄的图像的大小,然后将其指定给ImageView。然而,这仍然不起作用,即使我将其调整为100x100 其次,我没有将相机拍摄的照片分配给ImageView,但它仍然具有内存警告 我在这里

当我在iPhone上使用相机时,会收到内存警告。我也使用弧

当您拍摄照片并按下相机视图控制器上的“使用照片”按钮时,我会收到一条内存警告。其目的是一旦按下“使用照片”按钮,它就会更改ImageView的内容

我认为内存问题可能是因为捕获的图像是全屏的,而ImageView是250h 250w。但我尝试缩小相机拍摄的图像的大小,然后将其指定给ImageView。然而,这仍然不起作用,即使我将其调整为100x100

其次,我没有将相机拍摄的照片分配给ImageView,但它仍然具有内存警告

我在这里查看了其他答案,并尝试了上述两种方法,但仍然存在。我将在下面显示我的代码。这会影响我向应用商店提交的内容吗?当然,如果这是一个如此普遍的现象,这是一个错误或有一个解决办法?如果您可以查看提供的代码并发现错误或建议如何处理此内存警告,那将是一件非常棒的事情

除此内存警告外,我的应用程序已完成95%以上,因此即将提交

我的代码:

- (IBAction)takePhoto:(id)sender {

self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing=NO;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
     [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    [self presentViewController:self.imagePicker animated:YES completion:NULL];

}
else{
    [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [self presentViewController:self.imagePicker animated:YES completion:NULL];
 }



}

- (IBAction)choosePhoto:(id)sender {
self.imagePicker2 = [[UIImagePickerController alloc] init];
self.imagePicker2.delegate = self;
self.imagePicker2.allowsEditing=NO;
[self.imagePicker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker2 animated:YES completion:NULL];
}

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

self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGRect rect = CGRectMake(0,0,100,100);

UIGraphicsBeginImageContext( rect.size );
[self.image drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.snapImage setImage:picture1];

[self.uploadImageBtn setHidden:NO];
[self dismissViewControllerAnimated:YES completion:NULL];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

[self dismissViewControllerAnimated:YES completion:NULL];
}

我没有找到一个好的解决方案,但我不会将原始图像存储在属性中,因为原始图像占用大约30MB的内存。因此,不是:

self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
我把它改成:

UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
这样,图像在不再使用时会被破坏。注意:我已经在iPhone4系列和iPhone5上测试了这个新方法。内存警告仅出现在4系列上,而不是5系列上


环顾网络,已经有很多关于摄像头和iOS7的错误报告提交给了苹果。例如,当你不定期地启动相机时,它会显示一个黑色预览——这与iOS7有关,更重要的是iPhone4系列而不是5。这可能是处理器能力的不同之处——但我不确定。我的应用已获得应用商店的批准,因此内存警告不会成为问题-

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    [[NSURLCache sharedURLCache] removeAllCachedResponses];

}

清除我使用的“UIImagePickerController”类中的缓存,对我很有用

你找到这个问题的解决方案了吗,自从我升级到iOS 7后,我仍然面临这个问题。没有,我没有找到一个好的解决方案,但这有帮助:“我不会将原始图像存储在属性中,因为原始图像占用大约30MB的内存。”因此,与其
self.image=[info-objectForKey:UIImagePickerControllerOriginalImage]我将其更改为
UIImage*image=[info-objectForKey:UIImagePickerControllerOriginalImage]。这样,当图像不再使用时,图像将被删除。注意:我已经在iPhone4系列和iPhone5上测试了这个新方法。内存警告只出现在4系列上,而不是5系列上。环顾网络,已经有很多关于摄像头和iOS7的错误报告提交给了苹果。例如,当你不定期地启动相机时,它会显示一个黑色预览——这与iOS7有关,更重要的是iPhone4系列而不是5。这可能是处理器能力的不同之处——但我不确定。我的应用程序已获得AppStore的批准,因此内存警告将不会成为问题。谢谢您的响应,我在iPhone4系列中也收到了此警告。我的应用程序在iPad上运行正常。没问题,乐意帮忙;)记住,iOS7不是用iPhone4构建的,它是用iPhone5发布的。总是会有性能问题