DESTRUCTOR statement
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 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
destructor-body
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. The method’s logic must not reference, either directly or indirectly, statements that block for input (namely, the CHOOSE, INSERT, PROMPT-FOR, READKEY, SET, UPDATE, and WAIT-FOR statements).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 ]ExampleThe following example shows the definition of a 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.
See alsoCLASS statement, CONSTRUCTOR statement, DELETE OBJECT statement
OpenEdge Release 10.2B
|