In my understanding, Analyze is meant to be very literal, even simple-minded. 
Your method returns a retained object but you did not put "new" or "copy" in 
the method name. It assumes that you were following the naming convention and 
that your omission of "new" or "copy" was intentional. It therefore reported to 
you that the return of a retained object is an error. It is telling you that 
your code is wrong only in this very literal and simple-minded sense.

In fact, your comment in the last method, which does have "new" in its name, 
demonstrates that you are aware of the naming convention. Why did you not 
follow the convention in the other method? Add "new" or "copy" to the name and 
build it again. The Analyze error went away, right?

I figured this out a couple of years ago when I first applied Analyze to my own 
code. I spent hours parsing my memory management code and concluded that it was 
correct despite the Analyze errors. Then, on a whim, I added "new" and "copy" 
to several method names, and suddenly Analyze agreed that my code was correct. 
It is not smart enough to look ahead in the logic to see that -dealloc took 
care of the second retain. I'm not enough of a computer scientist to know if 
that is even possible without impractical levels of analysis.

At the time, the fact that Cocoa had started following a naming convention that 
had until then applied only to Core Foundation was documented exactly nowhere. 
I haven't looked since then, so I don't know whether it is now documented 
correctly.

Bill Cheeseman

On Sep 12, 2013, at 6:52 AM, Graham Cox <graham....@bigpond.com> wrote:

> But shouldn't it take into account that it was assigned to an ivar that is 
> retained until -dealloc? Or is it trying to tell me that it will leak if the 
> enclosing object happens to leak? If so, that would mean thousands of false 
> positives in most code, which doesn't appear to happen. This particular 
> object is a singleton that is never deallocated explicitly in fact - is that 
> it?

-- 

Bill Cheeseman - b...@cheeseman.name

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to