关闭

CGColorSpaceRef和CGGradientRef 的内存泄露

标签: 内存泄露
587人阅读 评论(0) 收藏 举报
分类:
-(void) createDefaultBrushTexture{
    UIGraphicsBeginImageContext(CGSizeMake(64, 64));
    CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext();
    UIGraphicsPushContext(defBrushTextureContext);

    size_t num_locations = 3;
    CGFloat locations[3] = { 0.0, 0.8, 1.0 };
    CGFloat components[12] = { 1.0,1.0,1.0, 1.0,
        1.0,1.0,1.0, 1.0,
        1.0,1.0,1.0, 0.0 };
    CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);

    CGPoint myCentrePoint = CGPointMake(32, 32);
    float myRadius = 20;

    CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), myGradient, myCentrePoint,
                                 0, myCentrePoint, myRadius,
                                 kCGGradientDrawsAfterEndLocation);

    UIGraphicsPopContext();

    [self setBrushTexture:UIGraphicsGetImageFromCurrentImageContext()];

    UIGraphicsEndImageContext();
}
解决方案:

Ok lets look at colorspace and see what the problem is. myColorspace is created CGColorSpaceCreateDeviceRGB retain count +1 and then never released. This is unbalanced and it needs to be released at the end. Add a CGColorSpaceRelease(myColorSpace);

"potential leak of an object stored into myGradient"

Same problem, creation with retain count +1, with no corresponding release. Add a CGGradientRelease(myGradient);



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:38295次
    • 积分:1274
    • 等级:
    • 排名:千里之外
    • 原创:93篇
    • 转载:3篇
    • 译文:0篇
    • 评论:2条
    最新评论