I am new to objective c and I don’t understand how there is a memory leak here:
MessageCustomCell *cell = [[MessageCustomCell alloc] initAutoreleaseWithLine:currentLine AndId:message.UID];
[[cell dateTime] setText:[formatter stringFromDate:message.Date]];
[[cell from] setText:message.From];
[[cell play] setTitle:@">" forState:UIControlStateNormal];
[formatter release];
return cell;
On the return cell; line the analyzer says that there is a “potential leak of an object allocated on line 207 and stored into cell.” This is the line where cell is allocated but I’m returning cell so how is this a leak?
Thanks in advance for the help!
The issue, based on the name, is you are trying to return an auto released object in an init function. The static analyzer makes assumptions that instance methods beginning with
initreturn ownership to the caller (increased retain count) even if you call itinitAutorelease. The same goes for methods that begin withnew. You will continue to get analyzer warnings until you change the name but what you are trying to do needs to be a convenience method of the class.