我在 2448 X 2448 像素图像上运行此代码。fullScaleView
也是 2448 X 2448(fullScreenView Rect:{{0, 0}, {2448, 2448}}
)。该方法完成后,应用程序内存从 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();
内存跳跃是因为图像很大 - 如果您确定不再需要它,则应该将使用返回图像的任何位置包装在自动释放块中:
e.g.
@autoreleasepool {
UIImage *theReturnedImage = yourmethodthatreturnstherenderedimage();
// do stuff with your image
}
不幸的是,在您使用完该映像之前,它会占用空间,因此您必须快速释放它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)