[英]iOS Received Memory Warning when cutting image
I tried to cut the image after taking photos. 拍照后我试图剪切图像。 This works fine on Non-Retina Device.
在非视网膜设备上可以正常工作。 But received memory warning on Retina Device.
但是在Retina设备上收到了内存警告。 I think there are some memory leaks when cutting the image cuz when I commented out, no issues.
我认为当我注释掉图像时,剪切图像cuz时会有一些内存泄漏,没有问题。
Code: 码:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CGSize imageSize = image.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat newDimension = 2360;
CGFloat widthOffset = 20 * [[UIScreen mainScreen] scale];
CGFloat heightOffset = 135 * [[UIScreen mainScreen] scale];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(newDimension, newDimension), NO, 0.);
[image drawAtPoint:CGPointMake(-widthOffset, -heightOffset)
blendMode:kCGBlendModeCopy
alpha:1.];
productImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self dismissViewControllerAnimated:NO completion:nil];
...
}
First time after taking photo, I got memory warning but not crashed. 第一次拍照后,我收到了内存警告,但没有崩溃。 When I try to reopen camera the app crashed.
当我尝试重新打开相机时,应用程序崩溃了。 Can somebody help me out?
有人可以帮我吗? Thanks
谢谢
@autoreleasepool {
...
productImage = UIGraphicsGetImageFromCurrentImageContext();
...
}
autoreleasepool might help it. autoreleasepool可能会有所帮助。 UIGraphicsGetImageFromCurrentImageContext returns autoreleased UIImage object and it remains for awhile until exiting autoreleasepool block or the end of the runloop on the main thread.
UIGraphicsGetImageFromCurrentImageContext返回自动释放的UIImage对象,该对象将保留一段时间,直到退出自动释放池块或主线程上的runloop结束。 Which part of your code should be enclosed by autoreleasepool, it depends on your code.
autoreleasepool应该将代码的哪一部分括起来,取决于您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.