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

Managing the object life-cycle

Any class-based object, which ultimately derives from Progress.Lang.Object, is automatically deleted during garbage collection when all references to that object have been removed, that is, when its reference count goes to zero.
As long as you need the object, you must ensure that you maintain an object reference to that object. You can always assign the object reference to another variable before it goes out of scope or pass it to another procedure, where you can continue to manage the object until you finally delete it or it is deleted by garbage collection.
You can assign an object reference to an ABL data element in one of the following ways:
*When you assign the object reference returned by a NEW function (in the context of a NEW statement) to an ABL data element that is defined as a compatible object type
*When you pass an invocation of the NEW function as an argument to a routine INPUT parameter defined as a compatible object type
If you invoke the NEW function as part of an expression (not in a NEW statement) in which the resulting object reference is never assigned to an ABL data element, the AVM automatically handles the deletion of this object reference when it is no longer in use (sometime after the statement where the expression appears completes execution). Such an object reference is thus consumed by the expression and is no longer accessible to your application.
For more information on obtaining object references from the NEW function and the NEW statement, see Creating a class instance.
To disable automatic garbage collection of class-based objects, use the No Garbage Collection (-nogc) client startup parameter. By default, the AVM automatically deletes class-based objects when there are no remaining references to the object. When -nogc is specified, the application assumes the responsibility of deleting these objects explicitly, using the DELETE OBJECT statement. If -nogc is specified, those objects that are not explicitly deleted are deleted when the session ends, and the AVM does not invoke any destructors for the class.
Garbage collection does not apply to handle-based objects.
An object may be deleted at any time using the DELETE OBJECT statement and the presence of outstanding references will not inhibit the destruction of the object. If you want to ensure that an object is deleted immediately, without waiting for garbage collection to occur, then use the DELETE OBJECT statement.
* DELETE OBJECT statement