I am using this code to get a screenshots of the window at various different times and putting the UIImage created into an array which is passed on to another UIViewController so that they can be all displayed back in a grid. I try to release the UIImage and the memory usage never goes down ... how can I use the image here once, and retain ownership so I can release the memory once it is displayed
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imagesArray addObject:image];
[image release];
UIGraphicsGetImageFromCurrentImageContext()
returns "an autoreleased image object containing the contents of the current bitmap graphics context."
When you add the image to imagesArray, NSMutableArray
does a retain on it, and
it's all you need. The memory will be released when the image is removed from the array.
You should not call release on image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With