Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Using the CLASS construct : Defining the class destructor : DESTRUCTOR statement
 
DESTRUCTOR statement
This is the syntax for defining a class destructor:

Syntax

DESTRUCTOR [ PUBLIC ]class-name ( ):

  destructor-body

END [ DESTRUCTOR ] .
Element descriptions for this syntax diagram follow:
class-name
The name of the class stripped of any relative path information. This is the class-name portion of the class-type-name defined by the CLASS statement.
destructor-body
The logic of the destructor, which can be composed of any ABL statements allowed within a method block, except that any RETURN ERROR or UNDO, THROW cannot raise ERROR beyond the level of the destructor block. The destructor logic is normally used to free up any dynamic handle-based objects or other system resources in use by the class.
Adding a destructor to the sample class definition results in the following code:
USING acme.myObjs.*.
USING acme.myObjs.Common.*.

CLASS acme.myObjs.CustObj INHERITS CommonObj:

  DEFINE PUBLIC VARIABLE iNumCusts AS INTEGER NO-UNDO.

  DEFINE PROTECTED TEMP-TABLE ttCustomer NO-UNDO
    FIELD RecNum  AS INTEGER
    FIELD CustNum LIKE Customer.CustNum
    FIELD Name    LIKE Customer.Name
    FIELD State   AS CHARACTER.

  DEFINE PRIVATE VARIABLE rCreditObj AS CLASS CreditObj NO-UNDO.
  DEFINE PRIVATE VARIABLE rMsg       AS CLASS MsgObj    NO-UNDO.

  CONSTRUCTOR PUBLIC CustObj ( ):
    rCreditObj = NEW CreditObj ( ).
    iNumCusts = 0.

    /* Fill temp table and get row count */
    FOR EACH Customer NO-LOCK WHERE Customer.CreditLimit > 50000:
      CREATE ttCustomer.      
ASSIGN
        iNumCusts          = iNumCusts + 1
        ttCustomer.RecNum  = iNumCusts
        ttCustomer.CustNum = Customer.CustNum
        ttCustomer.Name    = Customer.Name
        ttCustomer.State   = Customer.State.
    END.
    rMsg = MessageHandler("acme.myObjs.CustObj").
  END CONSTRUCTOR.

  ...

  DESTRUCTOR PUBLIC CustObj( ):
     EMPTY TEMP-TABLE ttCustomer.
END DESTRUCTOR.

END CLASS.
In this definition, the clean-up work of the class destructor includes emptying a temp-table of all the records that the class creates for it. Note that all the other class instances that this class creates are automatically deleted through garbage collection. For more information on ABL garbage collection, see Managingthe object life-cycle.