I’m having trouble understanding how the static analyzer in XCode is identifying possible leaks that involve singletons. In the code below, I get warned that there is a possible leak in the first line, and also in the first return statement. The analyzer places these warnings on the second return statement. Since I’m doing no allocations in these lines, I assume it is the access to the singleton, and its possible allocation, that is causing this warning. Can anyone explain to me what is going on here with the static analyzer?
if ((self.tableView.editing & ([[[[GroupList sharedGroupList] newGroup] linkArray] count] < [[GrazeConstants sharedGrazeConstants] maxLinksPerGroup])) |
(([[[[GroupList sharedGroupList] newGroup] linkArray] count] == 0) & !self.tableView.editing)) {
return ([[[[GroupList sharedGroupList] newGroup] linkArray] count]+1);
} else {
return ([[[[GroupList sharedGroupList] newGroup] linkArray] count]);
}
new-prefixed methods are equivalent to analloc+initpair according to Cocoa memory management conventions. The static analyzer is assuming that yournewGroupmethod is returning an object with a +1 retain count, not an autoreleased one.Rename the method (e.g.,
groupormakeGroup), or add theNS_RETURNS_NOT_RETAINEDattribute if you can’t change the name.