• 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 object release timing (for a NSCollectionView)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and object release timing (for a NSCollectionView)


  • Subject: Re: KVO and object release timing (for a NSCollectionView)
  • From: vincent habchi <email@hidden>
  • Date: Sat, 23 Jan 2010 10:48:31 +0100

Hi Corbin,

>> I have a NSButton in C to remove from the array controller the A object it represents. However, each time I click on that button, I first get a warning telling me that I remove an observed object before releasing the observer, and then the program crash,
>
> If you have a crash, it is always best to post the crash report.

Well, I wrote a workaround, so I can't give you a crash report anymore.
The crash happens in the KVO unregistering routine.

The problem is that when the represented object is removed from the array controller, the corresponding NSView is not immediately released. Instead, there is an implied CAAnimation (or something similar) that makes the NSView slowly fade away. Net result is that the NSView survives some tenths of a second after the represented object is released, and the KVO unregistering crashes.

The (very dirty) workaround is this: instead of immediately release the represented object, retain it, target it for delayed deletion, and then remove it from the array; the real deletion is triggered in the dealloc routine of the corresponding NSView (or subclass thereof) :

// Highly heterodox
- (void)dealloc {
	[super dealloc];
	[[[[NSApp delegate] appController] layerManager] removeTargetedCALayer];
}

I had to write it this way, instead of the more orthodox :

- (void)dealloc {
	[[[[NSApp delegate] appController] layerManager] removeTargetedCALayer];
	[super dealloc];
}

because the KVO removal takes place in the [super dealloc] routine…

Great WE,
Vincent_______________________________________________

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: KVO and object release timing (for a NSCollectionView)
      • From: Kyle Sluder <email@hidden>
References: 
 >KVO and object release timing (for a NSCollectionView) (From: vincent habchi <email@hidden>)
 >Re: KVO and object release timing (for a NSCollectionView) (From: Corbin Dunn <email@hidden>)

  • Prev by Date: Re: NSImage loads garbage every other time?!?
  • Next by Date: QTMovieLayer with CIFilter returning bigger content
  • Previous by thread: Re: KVO and object release timing (for a NSCollectionView)
  • Next by thread: Re: KVO and object release timing (for a NSCollectionView)
  • Index(es):
    • Date
    • Thread