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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to