I am creating a custom transition between two view controllers. To do this I am grabbing screenshots of custom areas on the top and bottom of the view in order to animate them out.
However, whenever I do this an ImageIO_JPEG_Data
is created (about 7 - 8 mb for each transition) that is never eliminated or released. (You can see three in the instruments screen shot below).
Trolling stackoverflow answers to similar questions on I have tried distinctly running this on the main thread with dispatch_async(dispatch_get_main_queue(), ^{
and adding an @autorelease
pool but to not avail.
Am I missing something or is there a better way to create these screenshots that would not create a memory leak?
//Get Top View
CGSize photoSize = CGSizeMake(self.view.frame.size.width, topHeight);
UIGraphicsBeginImageContextWithOptions(photoSize, NO, 0.0f);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.layer.contents = nil;
topTransitionView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, snapshot.size.width, snapshot.size.height)];
topTransitionView.image = snapshot;
//Get Bottom View
CGRect photoRect = CGRectMake(0, imageFrame.origin.y + imageFrame.size.height, self.view.frame.size.width,self.view.frame.size.height - (imageFrame.origin.y + imageFrame.size.height));
if (photoRect.size.height <= 0) {
photoRect.size.height =1;
}
UIGraphicsBeginImageContextWithOptions(photoRect.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, -photoRect.origin.x, -photoRect.origin.y);
[self.view.layer renderInContext:ctx];
UIImage *bottomSnapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.layer.contents = nil;
bottomTransitionView = [[UIImageView alloc]initWithFrame:CGRectMake(0, imageFrame.origin.y + imageFrame.size.height, bottomSnapshot.size.width, bottomSnapshot.size.height)];
bottomTransitionView.image = bottomSnapshot;