Re: Right place to unobserve notifications in a document
Re: Right place to unobserve notifications in a document
- Subject: Re: Right place to unobserve notifications in a document
- From: "Michael Ash" <email@hidden>
- Date: Mon, 18 Aug 2008 11:37:58 -0400
On Mon, Aug 18, 2008 at 5:59 AM, Negm-Awad Amin <email@hidden> wrote:
> Hi,
>
> for some teaching reasons I have a document class, which observes a
> notification. Of course I have to unobserve this notification, when the
> document is closed. Doing this in -dealloc is no good design (fuunctional
> overhead in -dealloc, garbage collection …).
There's nothing wrong with doing it in -dealloc, and in fact this is
the standard way to do it. Overhead is not a problem. That code has to
run *sometime*, and -dealloc is not in anybody's critical path the way
-finalize is. Garbage collection is not a problem, because
notification observers are held with weak references in a GC
environment, so you don't need to manually unobserve at all. Also note
that it's pretty rare and undesirable to write dual-mode code. If
you're running under GC, just forget about unobserving. If you're not,
then forget about problems with GC.
Mike
_______________________________________________
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