• 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: How to de-register value observers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to de-register value observers


  • Subject: Re: How to de-register value observers
  • From: Tron Thomas <email@hidden>
  • Date: Tue, 04 Sep 2007 18:53:53 -0700

Chris Hanson wrote:
Are you establishing the binding in Interface Builder or in code?

If you're establishing the binding in code by sending your custom view -bind:... in your NSWindowController subclass, best practice would be to send your custom view -unbind:... in "the opposite" method in your NSWindowController subclass.

For example, if you're setting up the binding in an override of the -[NSWindowController windowDidLoad] or -[NSWindowController awakeFromNib] method, it would be a good idea to tear down the binding in an override of the -[NSWindowController close] method. This way your uses of -bind:... and -unbind:... will be balanced.

I find that when I close the window, I get the following message in the debugger:

An instance 0x30fda0 of class <My Window Controller Class> is being deallocated while key value observers are still registered with it. Break on _NSKVODeallocateLog to start debugging.

One other thing you could do if you know the bound-to object will go away when the window closes is register your custom view for the appropriate NSWindow notification, and when the notification is posted, unbind your custom binding. After all, you're not "re-using" this view anyway, so you don't need to worry about re-establishing the binding again later; you're just going to load the nib anew creating a different view object with its own instance of the custom binding.


  -- Chris



I am establishing the binding in Interface Builder.

_______________________________________________

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


References: 
 >How to de-register value observers (From: Tron Thomas <email@hidden>)
 >Re: How to de-register value observers (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: compiler warning when attempting to save hex value in char in reusing it
  • Next by Date: Re: Adding to an applications menu.
  • Previous by thread: Re: How to de-register value observers
  • Next by thread: check if a file path is useable
  • Index(es):
    • Date
    • Thread