Syntax

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

DELETE OBJECT object-reference[ NO-ERROR ].
object-reference
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:

DELETE OBJECT myCustObj.         
Note: If you use DELETE OBJECT on an object reference but there is still another reference to that object, the other reference will become invalid. Therefore, unless you are sure that the object is no longer needed, it is best to allow garbage collection to delete class-based objects. You just need to be sure that any reference no longer needed is set to the Unknown value (?), or will naturally go out of scope.

There is one case where garbage collection will not occur and that is when there is a circular reference (for example, object A has a reference to object B and object B has a reference to object A). In this case, a link in the chain needs to be broken in order for garbage collection to free the objects involved. To break the chain, set one of the references to the Unknown value (?) or use DELETE OBJECT on the reference. But again, this is not appropriate if there are other references that need to remain valid.

There are other ways to create a circular reference, that do not only involves classes. One case is when a procedure (or class) instantiates a class object that then binds to a temp-table or dataset (via the BIND option) in the procedure. In this case, there is circular dependency: the procedure holds a reference to the class instance, and the class instance depends on the temp-table or dataset from the procedure (via the BIND option). The application code needs to break that circular reference before being able to delete the objects. Another situation that can cause circular references is a class that subscribes to an event in another class, if the class that has the event also has a reference to the class that subscribed to the event. In this case, make sure you unsubscribe from the event when done with it.

For more information on deleting class-based objects, see Delete 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 Construct an object. For more information on raising ERROR within a constructor, see Raise 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 ABL Reference and the Re-usable Objects Cache (-reusableObjects) startup parameter in 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 Initialize and delete static members.