Udostępnij za pośrednictwem


Sys.IDisposable dispose Method

Releases resources held by an object that implements the Sys.IDisposable interface.

objectVar.dispose();

Remarks

Implement the dispose method to close or release resources held by an object, or to prepare an object for reuse.

Note

The Sys.Component base class implements the IDisposible interface. If you create a component class derived from the Sys.Component base class, your class automatically inherits the IDisposible interface implementation.

When implementing this method, make sure that all resources held by your object or its dependencies are freed. To do so, propagate the call through the containment hierarchy. For example, an object A might allocate an object B, and an object B might allocate an object C. Object A's dispose implementation must call the dispose method of object B, which must in turn must call the dispose method of object C.

If an object's dispose method is called more than one time, the object must ignore all calls after the first call. For example, the object must not throw an exception if its dispose method is called multiple times.

Example

The following example shows a class that implements the IDisposible interface. The class definition implements the dispose method. The class is registered by invoking the Type.registerClass method and passing IDisposible in the interfaceTypes parameter. The dispose method of the instance is invoked so that it can release resources, which makes it safe for the code to delete the instance.

See Also

Reference

Sys.IDisposable Interface

Concepts

Creating Custom Client Script by Using the Microsoft Ajax Library