I need to load 4 images for simultaneous editing. When I load them from the users library, the memory exceeds 500mb and crashes.
Here is a log from a raw allocations
The reason you're having crashes and seeing such high memory usage is that you are missing the call to UIGraphicsEndImageContext();
-- so you are leaking memory like crazy.
For every call to UIGraphicsBeginImageContextWithOptions
, make sure you have a call to UIGraphicsEndImageContext (after UIGraphicsGetImage*)
.
Also, you should wrap in @autorelease
(I'm presuming you're using ARC), otherwise you'll still have out-of-memory crashes if you are rapidly processing images.
Do it like this:
@autorelease {
UIGraphicsBeginImageContextWithOptions(...);
..
something = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}