我漏水了,但看不到哪里。
这是我的部分代码:
+ (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];
但是,不知何故,在我释放包含进度 View 的对象后,这会导致指向 UIGraphicsGetImageFromCurrentImageContext 的泄漏。我该如何解决?
最佳答案
您需要在使用完后释放上下文。尝试添加以下内容
CGContextRelease(context);
关于ios - UIGraphicsGetImageFromCurrentImageContext 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16968569/