On Sep 9, 2013, at 3:49 AM, Marcel Weiher wrote:

> The pattern I adopted long ago to avoid that sort of situation is to have an 
> instance variable for my temps, in which case the code becomes:
> 
>       [self setTemp:newObject];
>       … do stuff …
>       [self setTemp:nil];
> 
> or if you prefer dot syntax:
> 
>       self.temp = newObject;
>       … do stuff …
>       self.temp = nil;
> 
> Even if you forget nilling, you at most have an extended lifetime of an 
> object, not a leak.  I also generally do the same in initialization code (but 
> not in dealloc).  For me, that simply got rid of reference-counting pain.  
> Completely.  Memory management is mediated by accessors, always.  And 
> accessors are generated.

This technique is not safe for reentrant methods, whether due to 
multi-threading or on the same thread through (possibly indirect) recursion.  
An automatic (local) temporary variable is private to that stack frame, while 
an instance variable is shared across the object, which usually means across 
many stack frames.

Something to keep in mind before adopting this.

Regards,
Ken


_______________________________________________

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