• 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: App fails on Yosemite - "Cannot remove an observer"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: App fails on Yosemite - "Cannot remove an observer"


  • Subject: Re: App fails on Yosemite - "Cannot remove an observer"
  • From: Lee Ann Rucker <email@hidden>
  • Date: Mon, 01 Dec 2014 21:28:54 +0000
  • Thread-topic: App fails on Yosemite - "Cannot remove an observer"

On Dec 1, 2014, at 1:08 PM, Andreas Höschler <email@hidden> wrote:

> Hi Kyle,
>
>>> Adding
>>>
>>> #ifdef __APPLE__
>>> - (void)setWindow:(NSWindow *)window
>>> {
>>> }
>>> #endif
>>>
>>> to my GSScrollView : NSScrollView subclass fixed (or at least worked around) the issue (no exception anymore and no apparent malfunction of the app).
>>
>> WOAAAAAHHHH. This is NOT the way to solve this problem!
>
> Of course not!! But it at least makes the application available for the time being (needed to be urgently fixed or at least worked around).
>
>> NSView and NSScrollView (may) do important work in -setWindow:! You just haven't noticed what you’ve broken yet.
>
> I have posted the methods and ivars I have added to my subclasses. I can't see any obvious conflict with Apples API modifications!?  And the app crashes in setWindow!? I see it that way. Apples implementation of NSScrollView::setWindow looks probably similar to this:
>
> - (void)setWindow:(NSWindow *)window
> {
>    // remove observer for _window::contentLayoutRect
>   [_window release];
>   _window = [window retain];
>   ...
>    // add observer for _window::contentLayoutRect
> }
>
> Do you agree?

No, because that's a really bad design pattern. It can bite you if you aren't careful - if, say, you don't call setters in dealloc because of KVO-triggered side effects, or anything else where the window's dealloc is called when you don't expect it. (Also I expect it's using ARC)

Since you can add observers on keypaths, I would do
[self addObserver:self forKeypath:@"window.contentLayoutRect"...
instead of
[window addObserver:self forKeypath:@"contentLayoutRect"...


And also, because it fits the behavior I've seen in other Apple bugs, the problem might be that there's not a "setWindow:nil" in there when it's all done - I have seen things that indicate they don't set delegates to nil, and since delegate is a weak ref, that means it can be dead and still referenced. Fine if everything is ARC, but not so good when there's a mix.
_______________________________________________

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: 
 >Re: App fails on Yosemite - "Cannot remove an observer" (From: Andreas Höschler <email@hidden>)
 >Re: App fails on Yosemite - "Cannot remove an observer" (From: Kyle Sluder <email@hidden>)
 >Re: App fails on Yosemite - "Cannot remove an observer" (From: Andreas Höschler <email@hidden>)

  • Prev by Date: Re: App fails on Yosemite - "Cannot remove an observer"
  • Next by Date: Re: [CALayer cornerRadius] vs. [NSBezierPath bezierPathWithRoundedRect:xRadius:yRadius]
  • Previous by thread: Re: App fails on Yosemite - "Cannot remove an observer"
  • Next by thread: [CALayer cornerRadius] vs. [NSBezierPath bezierPathWithRoundedRect:xRadius:yRadius]
  • Index(es):
    • Date
    • Thread