Re: Implementing binding with garbage collection.
Re: Implementing binding with garbage collection.
- Subject: Re: Implementing binding with garbage collection.
- From: "Ken Ferry" <email@hidden>
- Date: Thu, 8 Nov 2007 13:24:32 -0800
I'm sorry, I didn't mean to make my previous reply off-list. Here it is again:
Also, you aren't seeing -finally invoked because the correct method
name is -finalize.
> I seem to recall that, with GC enabled, I no longer have to worry
> about unregistering observers as they get zeroed out automagically
> when collected?
This applies to unregistering observers with NSNotificationCenter,
but unfortunately not to unregistering KVO observers. You still need
to remove these observers manually. You need to manually unbind as
well.
It's possible that this will be improved in the future. The extra
-removeObserver: calls won't hurt anything but code cleanliness if
they become unnecessary.
-dealloc is never invoked under gc. -finalize is. It's better if you
can avoid implementing finalize (turns out the things are really hard
to get right!) but unregistering a KVO observer is one of the reasons
you might need to.
In practice, it's often possible to guarantee for other reasons that
an object has been unregistered before it could be collected.
For example, you may rip down observers when a window is closed.
This is good practice. Especially in gc (but even without) doing
stuff besides releasing objects in memory in dealloc/finalize is sketchy.
Since anything in the entire framework can retain your objects, you
never really know when dealloc is going to be called, if ever.
Ken Ferry
Cocoa Frameworks
_______________________________________________
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