• 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: crash when using notification center and self
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crash when using notification center and self


  • Subject: Re: crash when using notification center and self
  • From: "Pierce T. Wetter III" <email@hidden>
  • Date: Tue, 6 Jun 2006 10:11:35 -0700


On Jun 6, 2006, at 8:56 AM, Bill Bumgarner wrote:

On Jun 5, 2006, at 11:01 PM, Tyler Riddle wrote:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"MBModelStateChanged" object:self
userInfo:info];

results in a SIGSEGV

My model is going to post notifications which the controller picks up
- I'm calling that code from the model and I have multiple models so I
need to be able to pay attention to only the right one at the right
time.


Is it wrong to pass "self" as the object when posting a notification?

Nope -- self works fine. The 'object:' parameter is used to only notify observers of that specific object for that specific notification (or observers that are interested in all instances of the notification).


Likely, you have registered an observer that was observing just notifications to 'self' that was released without first being removed from the notification center as an observer.

The notification center does not retain observers and, therefore, if an observer is released without first being removed as an observer from the notification center, you'll see crashes just like this.

So if you have a class that gets added to NSNotificationCenter as an observer dealloc is a good place to call:


 [[NSNotificationCenter defaultCenter] removeObserver: self];

Pierce



WOTip: Set things to NULL when you're done with them. It makes the JVM happy, and saves you GC time later.
More Tips: http://www.twinforces.com




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: crash when using notification center and self
      • From: Bill Bumgarner <email@hidden>
References: 
 >crash when using notification center and self (From: "Tyler Riddle" <email@hidden>)
 >Re: crash when using notification center and self (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: nsslider subclass not responding to mouseUp:
  • Next by Date: Re: crash when using notification center and self
  • Previous by thread: Re: crash when using notification center and self
  • Next by thread: Re: crash when using notification center and self
  • Index(es):
    • Date
    • Thread