Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
- Subject: Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
- From: "Georg C. Brückmann" <email@hidden>
- Date: Thu, 13 Aug 2009 00:00:52 +0200
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 (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