Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Managing the object life-cycle : DELETE OBJECT statement


This is the syntax for deleting an instance of a class:


DELETE OBJECT object-reference[ NO-ERROR ].
A data element containing a reference to an instantiated object.
For example, to delete the instance of the sample class, execute the DELETE OBJECT statement, as shown:
Note: Progress Software Corporation recommends that you allow garbage collection to delete class-based objects whose reference counts are 0. You may want to use DELETE OBJECT for an object with a circular reference or for an object while references to it still exist. Using DELETE OBJECT on an object that is referenced by another object will result in an invalid reference, requiring use of the ABL VALID-OBJECT() function. For more information, see VALID-OBJECT function.
For more information on deleting class-based objects, see Deleting an object.
Note: Within a constructor, you can also use DELETE OBJECT THIS-OBJECT to abort class instantiation, which sets the returned object reference to the Unknown value (?). However, Progress Software Corporation recommends that you use RETURN ERROR or UNDO, THROW to return ERROR from the constructor. This both aborts class instantiation and raises an ERROR condition that you can handle in the instantiating context. For more information on class instantiation, see Constructing an object. For more information on raising ERROR within a constructor, see Raising errors within an instance constructor.
During garbage collection and when a DELETE OBJECT statement executes, the AVM frees all allocated memory associated with the object reference and invokes the destructor for each class in the object’s class hierarchy, if one has been defined. An application can use the destructor for a class to release any resources that it has acquired during the execution of the object instance.
OpenEdge includes a performance tuning feature for ABL class-based applications that controls how the AVM deletes objects. The Re-usable Objects Cache (-reusableObjects) startup parameter specifies the number of deleted class objects that the AVM stores for later re-initialization. By default, -reusableObjects is set to 25. When you use -reusableObjects, the AVM transfers the deleted object for most ABL classes to a re-usable objects cache. If your application causes the AVM to instantiate the same class later, the stored object is re-initialized and removed from the cache. The re-initialized object has a new UUID and the same initial data as a new instance of the class. The re-use of the object saves much of the overhead of instantiating a class.
Note: The cache does not store .NET classes, .NET-derived ABL classes, classes with static elements, or classes compiled during your session.
For more information on the re-usable objects cache, see the DELETE OBJECT statement in OpenEdge Development: ABL Reference and the Re-usable Objects Cache (-reusableObjects) startup parameter in OpenEdge Deployment: Startup Command and Parameter Reference.
When the client session is shut down, the AVM deletes all remaining class instances, invokes the destructor for each class in the object’s class hierarchy (unless you specified -nogc), empties the re-usable object cache, and frees all resources associated with the classes.
Note: Deleting an instance of a class has no effect on any static members that have been initialized for the class type. static members of a class persist for the duration of an ABL session. For more information, see Initializing and deleting static members.