Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming

> ## Deleting a class instance

> You must delete an instantiated object when it is no longer needed, to avoid memory leaks during the execution of the application. To delete a class instance, you must use the `DELETE` `OBJECT` statement.

> This is the syntax for deleting a user-defined object:

> Syntax
>     DELETE OBJECT object-reference [ NO-ERROR ].

> Element descriptions for this syntax diagram follow:

> ``object-reference``

> A reference to an instantiated object.

> At run time, Progress frees all allocated memory associated with the object reference when it executes the `DELETE` `OBJECT` statement. Before doing this, Progress invokes the destructor for the object if one has been defined. An application can use the destructor to release any resources that it has acquired during the execution of the object instance. If an object is not explicitly deleted, it remains instantiated throughout the entire Progress session. When the client session is shut down, Progress deletes all remaining class instances and frees all resources associated with them. However, the destructor for all of these objects is not executed when the session ends and the application exits. If it is important for the destructor to be invoked, the application must explicitly delete all objects using the `DELETE` `OBJECT` statement prior to termination of the session. This might be necessary especially if the application has allocated system resources external to Progress itself.

> For example, to delete the instance of the sample class, you can use `DELETE` `OBJECT`, and then, as with Progress handles, set the object reference to the Unknown value (`?`) to assure that it cannot be mistakenly de-referenced, as shown:

>     DELETE OBJECT myCustObj.
>     myCustObj = ?.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095