How should this memory warning be avoided?

I have a method that returns CGPathand generates analyzer warnings. The method is declared in the protocol. Here is an example implementation that generates a warning:

"Potential leak of the object selected on line 47, and saved in the" path ":

- (CGPathRef)createPathForBounds:(CGRect)bounds key:(NSString *)key;
{
    if ([key isEqualToString:OvalColumn])
    {
        CGPathRef path = CGPathCreateWithEllipseInRect(bounds, NULL);
        return path;
    }

    return NULL;
}

Here is an example of a use that generates a warning: "Incorrect decrement of reference counting of an object that is not currently owned by the caller"

CGPathRef path = [self.delegate createPathForBounds:bounds key:someKey];

// Use the path to do some drawing

CGRelease(path);

Managing my memory correctly; I pass CGPaththe protocol saved from my method and I release it in the calling block, so I know that warnings can be ignored, but I would like to delete them altogether.

, ? ? ?

+5
1

- (CGPathRef)newPathForBounds:(CGRect)bounds key:(NSString *)key

, cf_returns_retained, (imo) .

+5

All Articles