ios – renderInContext对App Memory征税

我在2448 X 2448像素图像上运行此代码. fullScaleView也是2448 X 2448(fullScreenView Rect:{{0,0},{2448,2448}}).方法完成后,App内存从49.7MB跳至240MB,降至172MB.它保持在172MB.在这个renderInContext之后,应用程序似乎仍然不能在如此高的内存占用率下运行.我应该在何处以及如何强制释放? (iOS 7 XCode 5 ARC).

UIGraphicsBeginImageContextWithOptions(fullScaleView.bounds.size,fullScaleView.opaque,1.0);
[fullScaleView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetimageFromCurrentimageContext();
UIGraphicsEndImageContext();

解决方法

内存跳转是因为图像很大 – 如果你确定不再需要它,你应该在自动释放块中使用返回的图像进行包装:

例如

@autoreleasepool {
    UIImage *theReturnedImage = yourmethodthatreturnstherenderedimage();
    // do stuff with your image
}

不幸的是,在您使用完图像之前,它会占用空间,所以您只需要快速释放它.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...