• 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: Andy Lee <email@hidden>
  • Date: Mon, 18 Aug 2008 12:18:10 -0400

On Aug 18, 2008, at 11:51 AM, Negm-Awad Amin wrote:
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:.

I understand your concern -- you meant "functional overhead" in the sense of a design taboo, not a performance cost -- but in this case I think -dealloc is not only okay, but sometimes the only correct place to unregister a notification. Suppose an invariant of your design is that an object should receive notifications as long as, and only as long as, the object exists. If you unregister too soon, you may have an "alive" object that fails to get a notification. If unregister too late, the notification center will send the notification to a dangling pointer and your app will crash.


I think it's okay to unregister in -dealloc because conceptually it's related to releasing your ivars. You're explicitly dissolving a relationship between the object being dealloced and some other object -- a relationship you have to manually manage in the absence of garbage collection.

--Andy


_______________________________________________

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: Negm-Awad Amin <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>)
 >Re: Right place to unobserve notifications in a document (From: Negm-Awad Amin <email@hidden>)

  • Prev by Date: Re: Hex representation of NSString
  • Next by Date: Re: arch: posix_spawnp: /Developer/Tools/otest: Bad CPU type in executable
  • 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