ERASE statement

Purpose | Deallocate array memory and release it from memory.
Syntax | ERASE array[()] [, array[()]] ...
Remarks | Any memory assigned to the individual elements (if they are dynamic strings, Objects, Variants, etc.) is also released. ERASE deallocates all the memory for LOCAL, STATIC, and GLOBAL arrays. After an array is erased, attempting to access the array may produce a General Protection Fault (GPF). Local arrays are implicitly erased upon exit from the Sub/ Function/ Method/ Property that created them.

array

The name of the array to deallocate. Parentheses are optional, but are recommended for clarity of the source code.

One method to check if an array has been dimensioned without triggering a GPF is to use the LBOUND and UBOUND functions, as follows:

IF UBOUND(array) - LBOUND(array) = -1 THEN

' array() is not allocated

END IF

ERASE can deallocate an array that was passed as a parameter to a procedure, but only if the array was passed by reference (BYREF). To clear the contents of an array back to its initialized state, use REDIM or RESET.

Restrictions | Absolute arrays (those created by DIM...AT) are handled differently by ERASE. An explicit ERASE will release the individual elements of an absolute array, if needed, but the full data block is left as-is because no assumptions can be made as to its origin. It is the programmer's responsibility to ensure that the memory block overlaid by the absolute array is handled correctly. In an implied ERASE (Sub/Function/Method/Property exit) of a LOCAL absolute array, the internal array descriptor is deactivated, but no changes of any kind are made to the individual data elements or the full block. RESET may be used to set arrays to zeroes or empty strings without releasing the data block.
See also | ARRAYATTR, DIM, REDIM, RESET
Example | ERASE Array1$(), MyArray%()