Create and destroy a class instance
- Last Updated: October 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
The first requirement to program with classes is to
instantiate a class (create a class-based object). In ABL, you must
use the NEW function (classes) to create an instance
of a class. You can also assign the object reference for that instance to
an appropriate object reference data element using the NEW statement, which
calls the NEW function. This function invokes the
specified class constructor to complete class instantiation. To
help support OERA-compliant applications, you can also use the DYNAMIC-NEW statement,
which allows you to instantiate a class from an object type determined
at run time. You can also instantiate a class from criteria identified
at run time using the New( ) method of
the Progress.Lang.Class class.
The first class in an ABL application must be instantiated in a procedure file (not a class definition file). Thus, you must use an initial procedure file to start up a class-based application.
Objects (class instances) are automatically deleted (garbage
collected) by the AVM some time after no reference to the object
exists in the ABL session. However, you can force any class instance
to be deleted immediately using the DELETE OBJECT statement.
As with garbage collection, this statement invokes any destructor
specified for the class instance. If you or the AVM create a class
instance that is never assigned to an ABL data element (for example, when NEW appears
in an expression without assignment), you do not need to delete
the object; the AVM cleans it up automatically. Note that, once
initialized, static members of a class cannot be re-created or destroyed.
For more information on managing the creation and destruction
of class instances, see Manage the object life-cycle.
For more information on how the class hierarchy of an object is
created and destroyed, see Design objects: inheritance, polymorphism, and delegation. For more information on using
the NEW function and DYNAMIC-NEW statement
to instantiate a class, see Create a class instance.
For more information on initializing static class members, see Initialize and delete static members.