< Previous PageNext Page > Hide TOC

Cleaning the Undo Stack

NSUndoManager does not retain the targets of undo operations, for several reasons. Foremost is that the client—the object performing undo operations—typically owns the NSUndoManager; thus for the NSUndoManager to retain the target would create cycles. The NSUndoManager does contain references to the targets of undo operations, however, which it uses to send undo messages when undo is performed. If a target object has been deallocated, and an undo message is sent to it, errors result.

To remedy this, the client must take care to clear undo operations for targets that are being deallocated. This typically occurs in one of three ways:

In a more general sense, it sometimes makes sense to clear all undo and redo operations. Some applications might want to do this when saving a document, for example. To this end, NSUndoManager defines the removeAllActions method, which clears both stacks.



< Previous PageNext Page > Hide TOC


© 2002 Apple Computer, Inc. All Rights Reserved. (Last updated: 2002-11-12)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.