Defines a destructor for a class. A destructor
is a special type of method that the AVM invokes when an instance
of the class is deleted, either manually using the DELETE OBJECT statement or automatically through garbage collection.
Note: This statement is applicable only when used in
a class definition (.cls) file.
Syntax
DESTRUCTOR [ PUBLIC ]class-name ( ) :
destructor-body
|
-
[ PUBLIC ]
- Specifies the access mode for the destructor. For destructors, this is always PUBLIC
by default.
- As a PUBLIC resource, a destructor can be accessed indirectly by the defining class,
any of its inheriting classes, and any class or procedure that instantiates the class
object (that is, through an object reference), either by deleting the object instance
using the DELETE OBJECT statement or as a result of garbage collection.
-
class-name
- The name of the class this method destroys. This name must match the
class name portion of the type name for the class (that is, the
name of the class definition file excluding the .cls extension and
any package path information).
-
destructor-body
- The body of the destructor definition. Define the destructor
body using the following syntax:
.
.
.
method-logic .
.
.
.
END [ DESTRUCTOR ].
|
- method-logic
- The logic of the destructor, which can contain any ABL statements currently allowed within a
PROCEDURE block including class-related statements, but excluding the RETURN ERROR
statement.
-
This method typically contains logic to release system resources used by the
class instance, for example, by executing the DELETE OBJECT statement for handle-based objects created by the class or
by invoking the Dispose( ) method on .NET objects created by the class. However,
note that if the ABL class inherits from a .NET class, you cannot reliably
access members of the .NET super class from your class destructor, because .NET
might already have garbage collected it.
- END [ DESTRUCTOR ]
- Specifies the end of the destructor body definition. You must
end the destructor body definition with the END statement.
Example
The
following example shows the definition of a destructor:
DESTRUCTOR PUBLIC CustObj( ):
EMPTY TEMP-TABLE ttCust.
END DESTRUCTOR.
|
Notes
- You
can terminate a DESTRUCTOR statement with either a period (.) or
a colon (:), but typically use a colon (:).
- A destructor has no parameters and no return value.
- You never explicitly invoke the destructor to delete a class
instance. The method is implicitly invoked when the object is destroyed
manually by the DELETE OBJECT statement or automatically as a result
of garbage collection.
- The AVM also invokes the destructor of a given class if some constructor
in the same class hierarchy raises ERROR during object instantiation
and the constructor for the given class has already completed execution
during this instantiation.
- If your application does not require it, you do not need to
define a destructor for the class. ABL provides a default destructor
for classes that do not define one.