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: j o a r <email@hidden>
- Date: Mon, 14 Apr 2008 08:05:26 -0700
On Apr 14, 2008, at 5:29 AM, Tony Becker wrote:
In -awakeFromNib:, I use a instantiate and use a iVar. In dealloc,
I release it.
However, under the covers, I DON'T call [super -awakeFrommNib:],
because my parent didn't awake from his .nib.
But, in dealloc, I call [super dealloc], so my parent gets called
(and eventually NSObject)
Assuming that, in his awakeFromNib:, my parent used the same iVar
(or more correctly, I'm re-using it), he too will release it, which
is BAD.
The class that adds an instance variable is ultimately responsible for
clearing it in dealloc. You are not responsible for managing the
destruction of any instance variables of your superclass. If your
superclass expose an instance variable for connecting objects in IB,
you should trust that it deals with them in dealloc.
Directly accessing the instance variables of another class, including
your superclass, is fraught with peril and typically incorrect. Always
use accessor methods / properties for that type of situation.
Also keep in mind what I said earlier in this thread about calling out
from init/dealloc - It's dangerous!
j o a r
_______________________________________________
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