问题
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