Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

NSDisposable


Implemented by:
NSDisposableRegistry
NSUndoManager
Package:
com.webobjects.foundation

Interface Description


The NSDisposable interface declares one method, dispose, in which an object prepares for destruction. In dispose, an object should clear all references that other objects have to it. For example, if an NSDisposable object has assigned itself as another object's delegate, the NSDisposable object should set the other object's delegate to null in dispose, thus clearing the other object's reference to the NSDisposable object. You should implement this interface if your object is a delegate for another object.

NSDisposable is needed to clean up references to objects that ought to be destroyed. As an example, consider NSNotificationCenter. When an object registers for notifications, the notification center creates a reference to that object so that it can perform the notification at the appropriate time. Unless the object removes itself as an observer of the notification, the NSNotificationCenter's reference to the object prevents the object from being garbage collected.

By implementing NSDisposable, objects are given a chance to remove references that other objects have to them. This allows other objects to send dispose messages to NSDisposable objects when the NSDisposable objects are no longer needed. As an example, Direct to Java Client disposes of controllers when they're no longer needed, and subsequently, the NSDisposable controllers are garbage collected.


Guidelines

You should implement NSDisposable if your object is a delegate for another object. If you do implement NSDisposable, you should be sure that your dispose method will be invoked. If it won't be invoked automatically, you can add yourself to an appropriate NSDisposableRegistry. Known registries are provided by the com.webobjects.eoapplication classes EOController and EOArchive.



Instance Methods



dispose

public void dispose()

Invoked when the receiver should prepare itself for destruction. Implementations of this method should break connections that other objects have to the receiver, including unregistering for notifications, resigning as other objects' delegates, and so on.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents