The memory occupied by a dynamic object (array, class object, ...) is automatically freed when the object is no longer used or when closing the element (window, report, ...) in which the dynamic object was declared.
Delete is used to explicitly free the memory occupied by:
The use of Delete is optional. Delete allows the developer to quickly free the available memory space.
CustomerArray is dynamic array
CustomerArray = new dynamic array of 4 by 7 int
// Free the dynamic array
Delete <Name of Dynamic Object to Free>
<Name of Dynamic Object to Free>: Character string
Name of the dynamic object to free explicitly. This dynamic object can correspond to:
Special case: the dynamic arrays
- A dynamic array is automatically freed at the end of the lifetime of the variable (when the window is closed for example) or when allocating new dimensions.
- If a dynamic array is declared and created in a single line of code, Delete must not be used to explicitly delete the dynamic array. A runtime error will occur if Delete is used.
For more details, see Dynamic arrays.
Special case: the dynamic automation objects
The dynamic automation object is automatically freed at the end of the process containing its declaration or during a new allocation of the object.
Special case: the class objects and the dynamic class objects
To free an object, you also have the ability to use the following syntax:
You can also:
- Free the memory space used by a matrix with MatDelete.
- Free the memory space occupied by a matrix used by a chart with grDeleteAll.
Special case in Java/Android
The concept of destructor does not exist in Java/Android. Therefore, the code found in the destructor of a class will never be run.
An object is freed by the garbage collector when it is no longer referenced in the application. There is no way to foresee the moment when this operation occurs.
To force an object to be freed, you have the ability to assign it to NULL or to use the Free