DESTRUCTOR statement
- Last Updated: January 18, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
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
|
- [ PUBLIC ]
- Specifies the access mode for the destructor. For destructors, this is
always
PUBLICby default. - 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
.clsextension 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
PROCEDUREblock including class-related statements, but excluding theRETURN ERRORstatement. - END [ DESTRUCTOR ]
- Specifies the end of the destructor body definition. You must end the destructor
body definition with the
ENDstatement.
Example
The following example shows the definition of a destructor:
|
Notes
- You can terminate a
DESTRUCTORstatement 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 OBJECTstatement 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.
- Errors raised in a destructor are not subject to the rules implied by the
BLOCK-LEVEL ON ERROR UNDO, THROWorROUTINE-LEVEL ON ERROR UNDO, THROWdirectives.
See also
CLASS statement, CONSTRUCTOR statement, DELETE OBJECT statement