Using XCode 4.2, I am using the static analyser on code similar to the following:
@interface ArrayDimensions: NSObject
{
ArrayIndex *dims;
}
-(id) init: (int *)dims_;
@end
@implementation ArrayDimensions
-(id) init: (int *)dims_
{
self = [super init];
if(self)
dims = [[ArrayIndex alloc] make:dims_];
return self;
}
@end
The static analyser is reporting that the “method returns with a +1 retain count” and that the “Object leaked: allocated object is not referenced in this execution path”. This is a common type of warning throughout my code and, in each case, it would appear that the analyser fails to recognise that I am setting the value of an instance variable.
My question is whether I am indeed leaking memory or if the analyser is wrong.
The analyzer expects that methods return an autoreleased object, unless they are an
alloc/initpair or havecopyin the name, as per Objective-C method-naming guidelines. Try changing the name of your initialization method frommake:toinitWithDimensions:and see if that gets rid of the warning.