Re: static analyzer
Re: static analyzer
- Subject: Re: static analyzer
- From: Michael Ash <email@hidden>
- Date: Thu, 8 Jul 2010 01:01:52 -0400
On Wed, Jul 7, 2010 at 8:41 PM, Matt Neuburg <email@hidden> wrote:
> On Wed, 7 Jul 2010 17:54:58 -0400, Michael Ash <email@hidden> said:
>>> I get a false positive in *any*
>>> of my apps that uses NSURLConnection, for example:
>>>
>>> NSURLConnection* con = [[NSURLConnection alloc] initWithRequest:req
>>> delegate:self];
>>>
>>> That triggers a "potential leak" warning. Well, of course it is a
>>> *potential* leak. But it isn't a *real* leak, because I happen to know that
>>> I'm going to release this object in either connection:didFailWithError: or
>>> connectionDidFinishLoading:. (My code and memory management come right out
>>> of Apple's own examples here.) I know how NSURLConnections work; the static
>>> analyzer doesn't. But I would hardly call that a bug.
>>
>>I would call it potentially dangerous code. It's much better, IMO, to
>>place the connection into an instance variable and that way balance
>>all of your retains and releases. Each exception to the standard
>>memory management pattern that you make increases the odds of screwing
>>something up.
>
> Yes, I agree, and I did think of doing that to see if it would silence the
> warning. But a beginner might not realize that - and, as I say, my code is
> copied and pasted right out of Apple's example; it's up to Apple to change
> the example if it's dangerous...
>
> http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/URL
> LoadingSystem/Tasks/UsingNSURLConnection.html
Well, and I mean no offense to anyone reading this who's written some,
Apple sample code is not always all that great. In my experience, it's
often very good for learning how something can be accomplished, but
much less often a good example of style or good practices.
If a beginner wouldn't realize that it's dangerous, then all the more
reason to have the static analyzer complain about it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden