Programming Guide: Closing Your Part

# Programming Guide

## Closing Your Part

When the user closes the document containing your part, or when your part is deleted from its containing part, OpenDoc calls your part's ReleaseAll method, followed by its somUninit method. (If, when closing a document, the user specifies that changes be saved, your part's Externalize method is called before ReleaseAll.)

### The ReleaseAll Method

The ReleaseAll method is inherited from ODPersistentObject. Its purpose is to ensure that all your part's references to other objects and ownership of shared resources are relinquished before your part is itself deleted from memory. As a minimum, your override of the ReleaseAll method should:

- Call the Release methods of all reference-counted objects to which your part has references, including iterating through its private lists of embedded frames and display frames and releasing each one (at this point, all of them should have been released anyway)

- Remove any link specifications it has written to the clipboard

- Fulfill any promises it has written to the clipboard

- Relinquish all focuses that your part owns

- Clear the undo stack if it has written any undo actions to it

- Call the BaseRemoved method of any of your part's extensions

- Call the PartRemoved method of any embedded-frames iterators your part has created

Your part should not write itself to storage from within its ReleaseAll method. Your part's Release method, inherited from ODRefCntObject, is called under different circumstances from ReleaseAll. For information on implementing a Release method, see "Reference-Counted Objects".

### The somUninit Method

After it completes ReleaseAll, your part receives no subsequent method calls except to its System Object Model (SOM) object destructor somUninit. The somUninit method is inherited from the somObject class of SOM; when you subclass ODPart, you must override somUninit.

Your somUninit method should dispose of any storage created for your part object by the somInit method and any other storage related to additional instance variables of your part initialized during execution. In this method, do not perform any tasks that could fail.

[ Top | Previous | Next | Contents | Index | Documentation Homepage ]