- For simple variables (including fix-len arrays) declared anywhere, as follows:
Dim [Byref] [Shared] As datatype [Ptr] variablename
or
Static [Byref] Shared As datatype [Ptr] variablename
they always have a lifetime related to their scope. - For simple variables (including fix-len arrays) declared as follows:
Static [Byref] As datatype [Ptr] variablename
they always have a lifetime equal to the program duration, so irrelevant to their scope if there are declared in scope blocks (including procedure scopes).
- Generally, these allocation keywords are included in expressions used to assign or initialize a simple variable as above.
- Therefore, in this case, there are two distinct entities: a named pointer (or a reference) the first entity, pointing (or referring) to an allocated memory the second entity (unnamed).
- Do not confuse the two entities, each has its own lifetime (Deallocate, Delete, Imagedestroy deallocating only the second entity, not the first).
The string data being [re|de]allocated by string assignment, and array data being [re]allocated by Redim and deallocated by Erase (Erase does not destroy the descriptor but just re-initializes it).
Note:
Var [Byref] [Shared] variablename = expression
is equivalent to:
Dim [Byref] [Shared] As Typeof(expression) variablename = expression