• 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: More NSUndoManager woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More NSUndoManager woes


  • Subject: Re: More NSUndoManager woes
  • From: Graham Cox <email@hidden>
  • Date: Wed, 9 Apr 2008 23:24:02 +1000

Hi Alastair,

I'm not sure I fully understand it either - undo issues often make my head spin...

I *think* what's happening is that NSUndoManager is unhappy that - removeAllActionsWithTarget: is being called while it is in the process of discarding an invocation off its own stack. Indeed dealloc is only getting called once but the NSUndoManager is being re-entered and that's what it seems to be griping about. If there are no actions with that target I guess you might get away with it, but it's quite likely that there are (and targets are weak refs so they can still be there even when the object is being dealloced), so maybe NSUndoManager is trying to remove items from its stack while it is already iterating over it discarding the invocations that are dropping out.

It's perhaps analogous to the situation of removing objects from an array while iterating over it (but then again, who knows, the internal workings of NSUndoManager are off-limits).

However you might be right about the ref counting bug, so I'll try and re-examine it from that angle.


G.



On 9 Apr 2008, at 11:09 pm, Alastair Houghton wrote:
On 9 Apr 2008, at 12:23, Graham Cox wrote:

The docs for NSUndoManager state for -removeAllActionsWithTarget: that:

"An object that shares an NSUndoManager with other clients should invoke this message in its implementation of dealloc".

There is a problem with this - if the object being dealloced is itself the parameter to an undo invocation, which in anything more complicated than a trivial test case it is likely to be, then Cocoa goes into an infinite loop when it starts discarding these invocations off the bottom of the stack. The undo manager releases the invocation which releases the object, which calls - removeAllActionsWithTarget:self, and boom - it all falls over.

I'm not sure I see why you're getting into an infinite loop here. - dealloc should be being called at most once, right?


And it shouldn't be possible to get into a situation where your object is the parameter of an undo operation if you're already in that object's -dealloc routine. If that's what you're seeing, you have a reference counting bug I think.

Perhaps I'm misunderstanding the problem though?

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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: More NSUndoManager woes
      • From: Alastair Houghton <email@hidden>
References: 
 >More NSUndoManager woes (From: Graham Cox <email@hidden>)
 >Re: More NSUndoManager woes (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: More NSUndoManager woes
  • Next by Date: Re: want to keep a main window still, not close
  • Previous by thread: Re: More NSUndoManager woes
  • Next by thread: Re: More NSUndoManager woes
  • Index(es):
    • Date
    • Thread