next up previous contents index
Next: return Up: Control Structures Previous: Control Structures   Contents   Index

delete

delete [ variable]

Although not strictly a ``control'' keyword, the delete operator is handled at the control-block level. The operator will return the variable to its undefined state, as if before any assignment, and free the contents. After the delete operator is applied, the variable can be assigned to any data type.

Using the delete operator on an array will remove the array characteristics, so in general the variable can not subsequently be used as an array, except by assigning the variable to another array. The FreeArray function can be used to clear the data while still preserving the variable as an array, so that values can still be directly assigned at indices.

The delete operator applied to a handle will close the handle, as if the Close function was called. However, the handle will become an undefined variable after delete, rather than a scalar 0.

There are two reasons why this operator exists. The user may wish to delete unused variables that contain large data blocks to conserve memory. Also, the ConvertReply function can return a variable of any type, thus we must have an undefined variable to take the return, which is impossible in a loop without use of the delete operator.

The delete operator will generally delete the contents, however for arrays and strings, if the variable has an alias, the content will be retained in the alias, and all pointers or substrings remain valid. If the array or string variable has no alias, any associated pointers or substrings will also be reinitialized, and the underlying data will be freed from memory. Deleting a pointer or substring variable causes that variable to be undefined, but does not affect the pointed-to data.


next up previous contents index
Next: return Up: Control Structures Previous: Control Structures   Contents   Index
Stephen R. Whiteley 2024-09-29