I'm analyzing this block of code from an SDK and basing the kind of error on the answer of my latest question:
dasblinkenlight suggested me to create an NSData object for could releasing my uint8_t *bytes...
But here in this code:
/**
* this will set the brush texture for this view
* by generating a default UIImage. the image is a
* 20px radius circle with a feathered edge
*/
-(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();
}
I got the same kind of error on these lines:
potential leak of an object stored into 'myColorspace'
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
potential leak of an object stored into 'myGradient'
UIGraphicsPopContext();
I tried with:
free(myColorspace);
free(myGradient);
but I keep the same kind of issues, what can I do to resolve it
thanks in advance all your support
Listen to exactly what the errors are telling you.
"potential leak of an object stored into
myColorspace
"Lets look at colorspace and see if we can find the problem.
myColorspace
is createdCGColorSpaceCreateDeviceRGB
so retain count is +1, but then never released. This is unbalanced and it needs to be released at the end. We need to 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);
Do not use
free
on anything created with a frameworkCreate
function. The internal structure could be more complex, and free will not properly take care of all the memory. Use a correspondingRelease
function.