Function ClassDestroy() Foundation

Removes the class object of a dynamic class from memory.

ClassDestroy( <cClassName> | <oClassObject> ) --> lSuccess
The character expression <cClassName> indicates the name of the class to be removed from memory.
As an alternative, a reference to the class object can be passed to the function.

The return value is .T. (true) when the class object is removed from memory, otherwise it is .F. (false).


The function ClassDestroy() removes the class object of a dynamically created class from main memory. Dynamic classes are created during runtime by the ClassCreate() function. They are unknown at compile time. Therefore, they do not have a class function and are represented at runtime of a program only by a class object.

When a program uses a dynamic class, the corresponding class object should be removed from main memory when the class is no longer needed. Otherwise, the class object remains in memory and can be retrieved by the ClassObject() function at any time.

Creating and deleting dynamic classes

// The example demonstrates that the class object of a 
// dynamic class continues to exists even if there is no 
// variable left to hold a reference to the class object. 

#include "" 

   LOCAL oClass 

   oClass := ClassCreate( "MyClass",, {{"IVar",CLASS_EXPORTED}} ) 

   // Call method of the class object 
   ? oClass:className() 

   // Delete reference to the object 
   oClass := NIL 

   // Call method of the class object 
   ? ClassObject( "MyClass" ):className() 

   // Remove class object 
   ClassDestroy( "MyClass" ) 

   // This raises a runtime error 
   ? ClassObject( "MyClass" ):className() 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.