• 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: Implementing binding with garbage collection.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing binding with garbage collection.


  • Subject: Re: Implementing binding with garbage collection.
  • From: "Ken Ferry" <email@hidden>
  • Date: Thu, 8 Nov 2007 13:24:32 -0800

I'm sorry, I didn't mean to make my previous reply off-list.  Here it is again:

Also, you aren't seeing -finally invoked because the correct method
name is -finalize.

> I seem to recall that, with GC enabled, I no longer have to worry
> about unregistering observers as they get zeroed out automagically
> when collected?

This applies to unregistering observers with NSNotificationCenter,
but unfortunately not to unregistering KVO observers.  You still need
to remove these observers manually.  You need to manually unbind as
well.

It's possible that this will be improved in the future.  The extra
-removeObserver: calls won't hurt anything but code cleanliness if
they become unnecessary.

-dealloc is never invoked under gc.  -finalize is.  It's better if you
can avoid implementing finalize (turns out the things are really hard
to get right!) but unregistering a KVO observer is one of the reasons
you might need to.

In practice, it's often possible to guarantee for other reasons that
an object has been unregistered before it could be collected.
For example, you may rip down observers when a window is closed.
This is good practice.  Especially in gc (but even without) doing
stuff besides releasing objects in memory in dealloc/finalize is sketchy.
Since anything in the entire framework can retain your objects, you
never really know when dealloc is going to be called, if ever.

Ken Ferry
Cocoa Frameworks
_______________________________________________

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: 
 >Implementing binding with garbage collection. (From: Joshua Emmons <email@hidden>)

  • Prev by Date: Re: NSOpenGLView overlap
  • Next by Date: Re: Smart way to get "etched" borders in Leopard
  • Previous by thread: Re: Implementing binding with garbage collection.
  • Next by thread: NSAppleScript - executeAndReturnError & suspendExecution
  • Index(es):
    • Date
    • Thread