renderInContext taxes App Memory

自作多情 提交于 2019-12-22 08:07:29

问题


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();

回答1:


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:

e.g.

@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.



来源:https://stackoverflow.com/questions/19646833/renderincontext-taxes-app-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!