我有泄漏,我看不到哪里。
这是我的代码的一部分:
+ (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;
}
然后我使用返回的UIImage作为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];
但是,不知何故,在我发布包含Progress View的对象之后,这会导致指向UIGraphicsGetImageFromCurrentImageContext的泄漏。我该如何解决?
答案 0 :(得分:-3)
完成后,您需要释放上下文。尝试添加以下
CGContextRelease(context);