ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Classes and Interfaces → ABAP Objects - Overview → Classes → Components of Classes → Methods
The C Destructor
A destructor is a special method that is called automatically when an object is deleted. Destructors can be used to release resources used by the object that are not included in garbage collection. ABAP Objects do not currently have a destructor in which a regular ABAP processing block can be programmed.
Other versions: 7.31 | 7.40 | 7.54
internal use only
CLASS class DEFINITION.
PUBLIC SECTION.
METHODS destructor [NOT AT END OF MODE].
...
ENDCLASS
.
one
CLASS class IMPLEMENTATION.
METHOD destructor.
SYSTEM-CALL c-destructor 'name' USING attr.
ENDMETHOD.
ENDCLASS
.
This means that the destructor makes it possible to call a C routine name when an object is deleted. The routine must exist in the ABAP kernel to ensure that no syntax errors occur.
When the optional addition NOT AT END OF MODE
is used, the destructor is not executed if the
internal session is
closed anyway. A destructor is usually also executed at the end of a session and should mainly be used to release external resources that are not released automatically when the session is closed.
When the C routine is called, attributes attr1
, attr2
,
and so on, of the class of any complex data type can be passed on to the routine. If multiple parameters are to be passed, an appropriate data type must be defined.
During the lifetime of an internal session, the time at which the method destructor
is executed depends on when the
garbage collector
is started. When an internal session is closed, the destructors that are not declared with the addition
NOT AT END OF MODE
are executed for all objects. In the case of inheritance, the destructors of subclasses are executed before the destructors of superclasses.