Re: dealloc query for NSTableCellView
Re: dealloc query for NSTableCellView
- Subject: Re: dealloc query for NSTableCellView
- From: Roland King <email@hidden>
- Date: Wed, 04 Feb 2015 21:27:04 +0800
> On 4 Feb 2015, at 21:16, Jonathan Mitchell <email@hidden> wrote:
>
> In my arc app I dispose of observers in -dealloc.
> The pattern I have established seems to work well but one case has me rethinking my approach.
> Everything pivots around NSViewController -representedObject;
>
> - (void)setRepresentedObject:(id)object
> {
> if (self.representedObject) [self removeObservers];
> [super setRepresentedObject:object];
> if (self.representedObject) [self addObservers];
> }
>
> - (void)dealloc
> {
> if (self.representedObject) [self removeObservers];
> }
>
> In my query case I have subclassed NSTableCellView. The principle is the same, but the signatures now are:
>
> - (void)setObjectValue:(id)object
> {
> if (self.objectValue) [self removeObservers];
> [super setObjectValue:object];
> if (self.objectValue) [self addObservers];
> }
>
> - (void)dealloc
> {
> if (self.objectValue) [self removeObservers];
> }
If I have an observation pattern which is set up, and the previous one torn down, in setXXX:(id)xxx like you do then my dealloc usually goes
[ self setXXX:nil ]
which both removes the observers and sets the property to nil so it doesn’t happen again.
Your problem here seems to be that you’ve tied the property to the observers in the set, but you are removing the observers without nil’ing the property in dealloc, thus leaving yourself open to another setter getting called.
>
> Crucially I find that in this case after my subclass -dealloc the superclass -dealloc calls -setObjectValue : nil which causes observation warnings to be issued (I always try and clear these types of issues because at the very least they mask real problems) as _objectValue will still be non nil and [self removeObservers] gets called again.
>
> Is it normal for superclasses to message during dealloc?
> I could be triggering any sequence of non dealloc friendly actions as a result of the call to -setObjectValue:.
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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