CGColorSpaceRef和CGGradientRef 的内存泄露

-(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);



阅读更多
文章标签: 内存泄露
个人分类: 内存泄露
上一篇UILabel 添加中划线和下划线
下一篇AFNetworking和Reachability 的内存泄露
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭