• 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: Releasing ivars in -didTurnIntoFault. Should set to nil?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
      • From: Quincey Morris <email@hidden>
References: 
 >Releasing ivars in -didTurnIntoFault. Should set to nil? (From: Jerry Krinock <email@hidden>)
 >Re: Releasing ivars in -didTurnIntoFault. Should set to nil? (From: "Sean McBride" <email@hidden>)
 >Re: Releasing ivars in -didTurnIntoFault. Should set to nil? (From: Dave Keck <email@hidden>)

  • Prev by Date: Re: Two right buttons on UINavigationBar?
  • Next by Date: Re: NSOutlineView vertical text alignment
  • Previous by thread: Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
  • Next by thread: Re: Releasing ivars in -didTurnIntoFault. Should set to nil?
  • Index(es):
    • Date
    • Thread