renderInContext taxes App Memory

2019-05-09 11:13发布

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条回答
Ridiculous、
2楼-- · 2019-05-09 12:06

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.

查看更多
登录 后发表回答