• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why should we set ivars to nil in dealloc?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Why should we set ivars to nil in dealloc? (From: Ben Trumbull <email@hidden>)
 >Re: Why should we set ivars to nil in dealloc? (From: Bill Bumgarner <email@hidden>)
 >Re: Why should we set ivars to nil in dealloc? (From: Tony Becker <email@hidden>)

  • Prev by Date: Re: loading the universal bundle
  • Next by Date: Re: NSMatrix Content Binding
  • Previous by thread: Re: Why should we set ivars to nil in dealloc?
  • Next by thread: Re: Why should we set ivars to nil in dealloc?
  • Index(es):
    • Date
    • Thread