My personal preference is the latter example.  My general rule of thumb is that 
once I -release or -autorelease an object, I shouldn't interact with it 
anymore, since I have relinquished ownership of said object.

The only time I don't follow that guideline is when I'm working inside a method 
that has several different return routes, and cleaning up the appropriate 
objects at each point would just add to the complexity of the method (which 
could be argued is already too complex, but that's for another thread).  In 
this case, I'll autorelease the appropriate objects immediately after 
initialization, thereby sparing me from having to clean stuff up in every 
single one of the return conditions.

Dave

On Aug 30, 2010, at 9:29 AM, Vincent Habchi wrote:

> Hi everybody,
> 
> just an enquiry regarding coding style. What is considered best:
> 
> baz = [[[Foo alloc] init] autorelease];
> …
> return baz;
> 
> or
> 
> baz = [[Foo alloc] init];
> …
> return [baz autorelease];
> 
> ?
> 
> Thanks!
> Vincent

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

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

Reply via email to