On 12.08.2009, at 22:59, Dave Keck wrote:

I've found that there's never any reason not to reset a variable after
releasing it. IMO it's just good practice.

I agree with that point. You may want to declare a macro like this:

#define INVALIDATE_REFERENCE(obj) ([(obj) autorelease], (obj) = nil)

The reason I chose autorelease over release are situations like the following: You register as a delegate of some object. Then the referenced object sends you a delegate message, to which you respond by clearing your reference to the said object. If at this time you’re sending the object its last release message, it will be deallocated. After your delegate message implementation returns, however, the formerly referenced and now deallocated object may continue executing the method from which it sent you the delegate message. And this is where you’d get into trouble using release instead of autorelease – you’d be in NSZombie hell.

And while this issue may not be relevant to managed objects, it certainly is relevant in other situations.

– Georg_______________________________________________

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