• 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
Don't make me override -(void)release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Don't make me override -(void)release


  • Subject: Don't make me override -(void)release
  • From: glenn andreas <email@hidden>
  • Date: Thu, 27 Dec 2007 15:46:49 -0600

So I've got this view that is a collection of stuff (stored in an NSMutableDictionary, though there is also an NSMutableArray that provides "order"). Some of these items support additional views that are inside the original collection of stuff view (e.g., an NSColorWell, since there are no NSColorCells).

Normally, when the item is dealloced, it removes that view from the superview (i.e., -[Item dealloc] calls [myView removeFromSuperview]), and everything is good (I use [myCollection removeAllObjects] to remove everything).

However, for some items, the view observes the underlying item (so it will know that something changes and needs to update - for example, an NSTextView whose text is bound to the item). In this case, when I call [myCollection removeAllObjects], KVO logic kicks in and says "whoa, about to deallocate something that is still being observed, danger, danger, danger". So I need to either figure out some way to tell KVO to not care (because the first thing dealloc for this item does is unbind itself from the view, so it will handle the case), or else I need to have a wrapper that is upstream of KVO's check (namely, by overriding release).

For a document, overriding -[NSDocument close] will provide a way to unbind (the document), but there's no such thing here (nor is it practical to add an "about to remove" method, since the whole purpose of using an NSMutableDictionary is that it manages what is referenced and how).

Unfortunately, this leaves overriding release (to see if the referenceCount is <= 1, and if so, do the explicit unbinding). Since overriding release, an more importantly, using referenceCount for anything other than intellectual exercises, seem like bad things to do, I'm hoping there's a better pattern (especially one that could also work if I ever turn on gc)

So what's a good way to unbind objects that don't have clean cut release patterns (since this will only be released when the last reference is removed, and there's no obvious case of knowing, especially since it may be in the dictionary more than once under different keys, as well as the array that keeps the order, and if something is "hidden" is is removed from that array)?



Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next generation of fractal art




_______________________________________________

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: Don't make me override -(void)release
      • From: Charles Steinman <email@hidden>
  • Prev by Date: Re: Enable or Disable menuitem
  • Next by Date: Re: Don't make me override -(void)release
  • Previous by thread: Re: Enable or Disable menuitem
  • Next by thread: Re: Don't make me override -(void)release
  • Index(es):
    • Date
    • Thread