renderInContext对App Memory征税 [英] renderInContext taxes App Memory

查看:129
本文介绍了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)。

I'm running this code on a 2448 X 2448 pixel Image. fullScaleView is also 2448 X 2448 (fullScreenView Rect:{{0, 0}, {2448, 2448}}). The App memory jumps from 49.7MB to 240MB down to 172MB after the method is complete. It stays at 172MB. It doesn't seem like the app should still be running at such high a memory footprint after this one renderInContext. Where and how should I force a release? (iOS 7 XCode 5 ARC).

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


推荐答案

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

The memory jumps because the image is huge - if you are sure that you won't need it anymore, you should wrap wherever you are using the returned image in an autorelease block:

例如

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

不幸的是,直到你是完成使用图像,它将占用空间,所以你只需要快速释放它。

Unfortunately, until you are finished using the image, it will take up space, so you just have to release it quickly.

这篇关于renderInContext对App Memory征税的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆