• 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: Deallocation while key value observers still registered
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deallocation while key value observers still registered


  • Subject: Re: Deallocation while key value observers still registered
  • From: "Sean McBride" <email@hidden>
  • Date: Tue, 25 May 2010 15:12:07 -0400
  • Organization: Rogue Research Inc.

On Wed, 26 May 2010 03:08:31 +1000, Gideon King said:

>I have found the problem. In awakeFromNib, I have several calls like this:
>
>[self addObserver:self forKeyPath:@"thingy"
>options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
>context:NULL];
>
>And in the dealloc method, I have:
>
>[self removeObserver:self forKeyPath:@"thingy"];
>
>for all the same key paths.
>
>All looked normal enough. But in the init method of the class, I was
>loading a nib that had my class as the file's owner, as well as being a
>view controller for another view. Therefore, awakeFromNib was being
>called twice, and although the dealloc was removing one set of
>registrations, the other set was being left. In my core data classes, I
>have all this wrapped in a boolean that avoids starting observing more
>than once, but I wasn't doing that in this part of my code.
>
>I found the -observationInfo method useful in tracking this down - I
>knew there must be some method like this, but had not found it before.
>
>Thanks for the suggestions etc.

Glad you've tracked it down.  Just a comment though: my understanding is
that calling removeObserver from dealloc is, in general, discouraged.
See here for some reasoning:

<http://www.karppinen.fi/analysistool/>

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

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: Deallocation while key value observers still registered
      • From: Roland King <email@hidden>
References: 
 >Re: Deallocation while key value observers still registered (From: Roland King <email@hidden>)
 >Re: Deallocation while key value observers still registered (From: aglee <email@hidden>)
 >Re: Deallocation while key value observers still registered (From: Kyle Sluder <email@hidden>)
 >Re: Deallocation while key value observers still registered (From: Gideon King <email@hidden>)

  • Prev by Date: Crash trying to unarchive webview from IB document
  • Next by Date: Re: Crash trying to unarchive webview from IB document
  • Previous by thread: Re: Deallocation while key value observers still registered
  • Next by thread: Re: Deallocation while key value observers still registered
  • Index(es):
    • Date
    • Thread