繁体   English   中英

UIGraphicsGetImageFromCurrentImageContext泄漏

[英]UIGraphicsGetImageFromCurrentImageContext leaking

我有泄漏,我看不到哪里。

这是我的代码的一部分:

+ (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的泄漏。 我该如何解决?

完成后需要释放上下文。 尝试添加以下内容

CGContextRelease(context);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM