Re: Avoiding KVO in dealloc?
Re: Avoiding KVO in dealloc?
- Subject: Re: Avoiding KVO in dealloc?
- From: Kiel Gillard <email@hidden>
- Date: Tue, 4 Aug 2009 10:03:09 +1000
On 04/08/2009, at 9:46 AM, Kyle Sluder wrote:
On Mon, Aug 3, 2009 at 4:35 PM, Todd
Heberlein<email@hidden> wrote:
Both methods seem to me to do the same thing (releasing foo), but I
presume
the first one would trigger any KVO observers where as the second
wouldn't.
Is that why the simple "release" is used instead of a setter in the
dealloc
methods, to avoid KVO? Is this a general Cocoa pattern?
Yes, it's a general pattern. Not just to avoid KVO, but any custom
accessor/mutator behavior.
The rule of thumb is never use your accessors/mutators inside -init or
-dealloc, and always use them elsewhere.
Unless, of course, you have code in your setter method that handles
changes to and from nil. For example, you may add or remove self as an
observer for keypaths of an different object value. This would save
repeating the change handling code in your init, setter and dealloc
methods.
Kiel
_______________________________________________
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