I have custom UIView
drawing in drawRect
.
I don't know the C APIs that well so I'm not sure what memory rules they require. The Objective-C rules are pretty simple and state that you release anything you own via init
retain
or copy
but the C function CGGradientCreateWithColorComponents
is not Objective-C and the Product > Analyze reports that it is a potential leak.
Is it necessary to release the results of this function, and if so, how? And in general, when it comes to these APIs, is there any easy way to know if a function is allocating memory that you need to manually release?
UPDATE: Here is the code, thanks to the information in the answers so far. I'm getting incorrect decrement
error now:
CGGradientRef theGradient=[self makeGradient:YES];
//do something with theGradient in my drawing
CGGradientRelease(theGradient); // this line Analyze says incorrect decrement of object not owned by caller
And in makeGradient
I have:
- (CGGradientRef)makeGradient:(BOOL)red{
CGGradientRef gradient;
//create my gradient
return gradient;
}