Why does this leak?
The arrayOfPerformances is a NSMutableArray, (nonatomic, retain) property that is synthesized.
The currentPerformanceObject is a Performance *, (nonatomic, retain) property that is synthesized.
Performance is a custom class
if(self.arrayOfPerformances == nil)
{
self.arrayOfPerformances = [[NSMutableArray alloc]init];
}
[self.arrayOfPerformances addObject:currentPerformanceObject];
[currentPerformanceObject release];
currentPerformanceObject = nil;
You are creating a new array and retaining it at the same time in this line, because you are invoking a
(retain)property setter with the dot notation:Because of that, the locally-created array is leaking because you don’t release it. You should autorelease that array, or create a temporary local var, assign, then release the local var, like so: