0
votes

Hi everyone i am running my code through the analyzer tool in the IDE where i am getting an indication in the dealloc and saying "incorrect decrement of the reference count of an object that is not owned at this point by caller" i am creating an NSArray and releasing properly my code sample is below

myClass.h

{                                                         
NSArray *arrayOfChapters;

}
@property (nonatomic, retain) NSArray *arrayOfChapters; 

@end

myClass.m:

-(void)parseAndLoadChaptersAndPages{
self.arrayOfChapters = chapterLoader.arrayOfChapters;
}
-(void)dealloc{
    [self.arrayOfChapters release];
    [super dealloc];
}

can any one tell me the problem why it is giving me the warning.Thanks in advance.

1
you did not call [super dealloc] in dealloc. Also try [arrayOfChapters release] instead of [self.arrayOfChapters release]. - user971401
Since you using properties, you should let the setter release the object. Do self.arrayOfChapters = nil instead. - tarmes

1 Answers

0
votes

You can either release the ivar directly ([arrayOfChapters release]), or you can set the property to nil (self.arrayOfChapters = nil) and the setter method will release the ivar for you.

The object owns the ivar arrayOfChapters, but not necessarily the return value of the arrayOfChapters method that you are calling using the property syntax. It's a bit confusing because both the ivar and the method have exactly the same name. In this case the arrayOfChapters method returns the ivar, so it's not a problem. However the analyser thinks the method could theoretically return a different object, in which case you would be over-releasing that object.