• 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: KVO and dealloc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and dealloc


  • Subject: Re: KVO and dealloc
  • From: DumberThanDanQuayle <email@hidden>
  • Date: Fri, 24 Sep 2004 06:45:59 -0400


On Sep 24, 2004, at 6:23 AM, Jeff Gilbert wrote:

Am I making things too complicated here?

No.


setGroups tells each Group object to removeObserver to stop KVO on the document bonds. So, as the document is deallocing, all of the KVO observations from groups are removed. However, as soon as I enter my document dealloc, I get the following message in the Run window:

An instance 0x3418c0 of class BondDocument is being deallocated while key value observers are still registered with it. Break on _NSKVODeallocateLog to start debugging.

Then, I quickly get a signal 11.

I realize that there are still observers, but I plan to remove them during dealloc.

You have to remove the observers before dealloc is called.

I can solve the problem by moving [self setGroups:nil] to the close method, as in

This is basically what I do for my objects.


Following the Cocoa mantra "Things are simpler than they seem", it seems that this is too complicated, in that it breaks from the tradition of releasing everything in dealloc. Or am I just being too sensitive? Should I just move all of my dealloc stuff to close?

This is perhaps my least favorites parts of the KVO implementation and the reason is that you can not be sloppy with removing observers either. If the object removed has not registered, you will get a crash. I have spent a lot of time on this issue.



The other thing you should be aware of is that observers must be removed in the same "style" as they are added. Mixing "to one" and "to many" techniques is not allowed.


See this post for more details:

http://www.cocoabuilder.com/archive/message/2004/1/17/99052

_______________________________________________
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: KVO and dealloc
      • From: Jeff Gilbert <email@hidden>
References: 
 >KVO and dealloc (From: Jeff Gilbert <email@hidden>)

  • Prev by Date: KVO and dealloc
  • Next by Date: Re: How to extend Safari -> Context-Menu, Plugin, traps
  • Previous by thread: KVO and dealloc
  • Next by thread: Re: KVO and dealloc
  • Index(es):
    • Date
    • Thread