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: Negm-Awad Amin <email@hidden>
- Date: Mon, 18 Aug 2008 17:51:54 +0200
Am Mo,18.08.2008 um 17:37 schrieb Michael Ash:
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
Argh, yes, I forgot this.
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.
Thanks a lot!
With the fact above, -dealloc seems to be a nice place, because it is
*not* executed running garbage collection.
But anyway I do not think, that doing something else then memory
management in -dealloc is good design. Normally I unregister
observation in delegate methods like -applicationWillTerminate:.
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
Amin Negm-Awad
email@hidden
_______________________________________________
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