【发布时间】:2014-05-29 20:46:56
【问题描述】:
虽然我会在 UIImagePickerController 完成拍照后调整图像大小,但我的仪器配置文件显示每次拍照时调用 ImageIO_PNG 都会占用大量内存 (40 MB+)。这是我的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
@autoreleasepool {
if (myImageView.image == nil) {
myImageView.contentMode = UIViewContentModeScaleAspectFill;
UIImage *topImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGRect rect = CGRectMake(0,0,320,440);
UIGraphicsBeginImageContext( rect.size );
// use the local image variable to draw in context
[topImage drawInRect:rect];
UIImage *topResized = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
myImageView.image = topResized;
image = nil;
info = nil;
[picker dismissViewControllerAnimated:NO completion:nil];
[picker removeFromParentViewController];
【问题讨论】:
-
一方面,在这段代码的底部,topImage、info 和picker 仍然被引用,所以它们仍然会被锁定在内存中。不知道你为什么要获取 image 和 topImage (在这种情况下它们是同一个对象的别名)
标签: ios memory png uiimagepickercontroller