Is the scope of what Xcode's "Build and Analyze" will catch as a leak supposed to be this limited?

Posted by Ranking Stackingblocks on Stack Overflow See other posts from Stack Overflow or by Ranking Stackingblocks
Published on 2010-04-29T16:09:43Z Indexed on 2010/04/30 4:17 UTC
Read the original article Hit count: 182

It doesn't care about this:

NSString* leaker()
{
 return [[NSString alloc] init];
}

I thought it would have been smart enough to check if any code paths could call that function without releasing its return value (I wouldn't normally code this way, I'm just testing the analyzer).

It reports this as a leak:

NSString* leaker()
{
 NSString* s = [[NSString alloc] init];
 [s retain];
 return s;
}

but NOT this:

NSString* leaker()
{
 NSString* s = [[NSString alloc] init];
// [s retain];
 return s;
}

which seems particularly weak to me. Does it only analyze within the local scope? If the tool can't pick up on things like this, how can I expect it to pick up on actual mistakes that I might make?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about xcode