• 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: Crash when loading NSViewController view with NSArrayController [solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash when loading NSViewController view with NSArrayController [solved]


  • Subject: Re: Crash when loading NSViewController view with NSArrayController [solved]
  • From: Lee Ann Rucker <email@hidden>
  • Date: Mon, 01 Oct 2012 12:43:58 -0700

On Sep 30, 2012, at 11:38 AM, Kyle Sluder wrote:

> On Sun, Sep 30, 2012, at 10:57 AM, Lee Ann Rucker wrote:
>> Weird that you didn't get the warning, but we've switched to the pattern
>> of
>>
>> [self addObserver:self forKeyPath:@"ctrl.selectedObjects.someString"...
>>
>> and that's saved countless headaches. You can remove your own observers
>> in dealloc so you never need to worry about when to remove the observer.
>
> Self-observation has always been a code smell to me. I suppose it's a
> lot better now that we have -removeObserver:forKeyPath:context:.
>
> In general, it is not a good idea to rely on -dealloc for cleanup of
> anything other than object references (that is, sending -release to
> strong ivars). Any other resource that requires explicit management
> (NSNotificationCenter registration, KVO, file handles, etc.) should not
> be managed in -dealloc unless that resource is *explicitly* tied to the
> lifetime of the object (a reuse pool, logging).
>

> I'd add and remove my observation in -setCtrl:. Or, since this is a view
> controller, perhaps add an explicit teardown method
> (-removeViewFromWindow or -windowIsClosing or something) and remove my
> observation there.
>


We've tried that. Either way you have to do cleanup somewhere; dealloc isn't the best place, but not all objects have nice convenient teardown hooks like windows and views do. Doing this in a setter means custom setters all over the place, so no nice @synthesize, and fun when a subclass needs to add a different set of observation values. Plus you'll have to call a setter in dealloc or duplicate the removeObserver code, neither of which are optimal.



_______________________________________________

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

  • Prev by Date: Re: App won't launch after a crash
  • Next by Date: FS item in trash
  • Previous by thread: Re: Compiling GC apps under OS X 10.8
  • Next by thread: FS item in trash
  • Index(es):
    • Date
    • Thread