• 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: Right place to unobserve notifications in a document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Right place to unobserve notifications in a document
      • From: "Michael Ash" <email@hidden>
    • Re: Right place to unobserve notifications in a document
      • From: Andy Lee <email@hidden>
References: 
 >Right place to unobserve notifications in a document (From: Negm-Awad Amin <email@hidden>)
 >Re: Right place to unobserve notifications in a document (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Hiding NSTableColumn causes other columns to shrink
  • Next by Date: Re: Hex representation of NSString
  • Previous by thread: Re: Right place to unobserve notifications in a document
  • Next by thread: Re: Right place to unobserve notifications in a document
  • Index(es):
    • Date
    • Thread