I have a method that returns a CGPath
and is generating analyzer warnings. The method is declared in a protocol. Here is an example implementation that is generating the warning:
"Potential leak of an object allocated on line 47 and stored into 'path'":
- (CGPathRef)createPathForBounds:(CGRect)bounds key:(NSString *)key;
{
if ([key isEqualToString:OvalColumn])
{
CGPathRef path = CGPathCreateWithEllipseInRect(bounds, NULL);
return path;
}
return NULL;
}
Here is example usage that is generating the warning, "Incorrect decrement of the reference count of an object that is not owned at this point by the caller"
CGPathRef path = [self.delegate createPathForBounds:bounds key:someKey];
// Use the path to do some drawing
CGRelease(path);
My memory management is correct; I'm passing back a retained CGPath
from my protocol method and I'm releasing it in the calling block, so I know the warnings can be ignored, but I'd like to remove them altogether.
Am I missing a naming convention that will make the analyzer happy? Can functions be defined in protocols? How will subclassing work?
onLowMemory() raises when the system global memory is low. If the global memory is okay but your process takes more than 24MB on old Android devices, it will crash and you'll never get a low memory warning.
Go to Settings > General and go through your apps that have the most data. If your streaming or other apps occupy a couple of gigs and you don't have anything downloaded on those services, uninstall the apps and reinstall them. This will clear out the cache.
As per Apple, a memory leak is:Memory that was allocated at some point, but was never released and is no longer referenced by your app. Since there are no references to it, there's now no way to release it and the memory can't be used again.
- (CGPathRef)newPathForBounds:(CGRect)bounds key:(NSString *)key
a detailed note on the topic can be found here
alternatively, you could have chosen to use the attribute cf_returns_retained
, but it's best (imo) to favor naming conventions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With