I am running this code with no autorelease pool in place under ARC:
- (NSString*) outName {
if (!outName) {
outName = [[NSString alloc] initWithFormat:@"whatever"]; // or stringWithFormat
}
return outName;
}
The debugger says that it's leaking the single outName
instance each time with no pool in place.
This does not happen if I change the code to
- (NSString*) outName {
if (!outName) {
outName = @"whatever";
}
return outName;
}
Which I cannot do (this example is obviously simplified). Also, the leak message disappears if I create an autorelease pool in the calling code (which I would like to avoid).
Why is ARC insisting on autoreleasing this object, which is held in a strong
property? And more importantly, how can I avoid this warning?