Re: Why should we set ivars to nil in dealloc?
Re: Why should we set ivars to nil in dealloc?
- Subject: Re: Why should we set ivars to nil in dealloc?
- From: Jerry Krinock <email@hidden>
- Date: Sun, 13 Apr 2008 12:27:24 -0700
On 2008 Apr, 13, at 10:48, Ferhat Ayaz wrote:
I see in some Apple's Cocoa examples that ivars are set to nil in
the dealloc method...why is it necessary...?
Usually it is not, but sometimes it is. I can't remember the specific
examples right now, but maybe to avoid a retain cycle, some other
object may have a weak reference to the ivar, or the ivar may have
been made a delegate of some object. Messages to nil result in no-op
but messages to deallocced objects result in a crash.
I suppose that if you always accessed ivars using their getter and
never kept a reference around for later, you'd be safe, but maybe
there are some circumstances when you don't want to do that.
_______________________________________________
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