-(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 createdCGColorSpaceCreateDeviceRGB
retain count +1 and then never released. This is unbalanced and it needs to be released at the end. Add aCGColorSpaceRelease(myColorSpace);
"potential leak of an object stored into
myGradient
"Same problem, creation with retain count +1, with no corresponding release. Add a
CGGradientRelease(myGradient);