• 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: Sun, 13 Apr 2008 12:41:42 -0700


On Apr 13, 2008, at 12:27 PM, Jerry Krinock wrote:
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.


This is not related to retain cycles at all.

In Non-GC, having a pointer to an object doesn't imply ownership. In GC it does (unless __weak), but the collector is smart enough to detect cycles.


Messages to nil result in no-op but messages to deallocced objects result in a crash.


...but if your code is designed in a way where messages are sent to deallocated objects, I would say that you should solve that problem, and not set your instance variables to nil. Fix it at the source.

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: 
 >NSTextField vertical sizeToFit (From: Jeff <email@hidden>)
 >Why should we set ivars to nil in dealloc? (From: Ferhat Ayaz <email@hidden>)
 >Re: Why should we set ivars to nil in dealloc? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Cocoa-dev Digest, Vol 5, Issue 600
  • Next by Date: Re: Why should we set ivars to nil in dealloc?
  • 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