3

I have a leak and I can't see where.

This is part of my code:

+ (UIImage *) imageWithColor:(UIColor *) color andSize:(CGSize) size {

    UIGraphicsBeginImageContext(size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));

    UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();    

    return colorImage;
}

and then I use the returned UIImage as the track and progress images of a UIProgressView

UIImage* trackImage = [ImageUtils imageWithColor:[UIColor blackColor] andSize:CGSizeMake(self.myProgressView.frame.size.width, 3)];
UIImage* progressImage = [ImageUtils imageWithColor:[UIColor whiteColor] andSize:CGSizeMake(self.myProgressView.frame.size.width, 3)];

[self.myProgressView setTrackImage:trackImage];
[self.myProgressView setProgressImage:progressImage];

But, somehow, after I released the object containing the Progress View, this causes a leak pointing to UIGraphicsGetImageFromCurrentImageContext. How can I fix it?

Odrakir
  • 4,254
  • 1
  • 20
  • 52
  • 1
    there is no leak in the code you show here – Daij-Djan Jun 06 '13 at 18:03
  • Possible duplicate of [UIGraphicsGetImageFromCurrentImageContext memory leak with previews](http://stackoverflow.com/questions/5121120/uigraphicsgetimagefromcurrentimagecontext-memory-leak-with-previews) – Cœur Dec 24 '16 at 05:50

1 Answers1

-3

You need to release the context after you are finished with it. Try adding the following

CGContextRelease(context);
THE_DOM
  • 4,266
  • 1
  • 18
  • 18