Hello Snorri,
your observation is correct: "once memory is allocated, it never gets released, only reused if possible"
Array elements can not be released while the array is alive. This is an (incomplete) workaround to avoid crashes when dereferencing array elements used in INPUTs or used as host-variables in CURSORs.
Informix-4GL can create at runtime references to array-elements. Examples: INPUT array[index].*, DECLARE cursor-name CURSOR FOR SELECT ... INTO array[index].*. The runtime assumes: the referenced array element is alive. A better saying for "assumes" is "blindly trusts". For exactly this reason each array element once created can not be released.
Can not be released? There is an (unsafe) trick:
DEFINE a DYNAMIC ARRAY OF INT
...
CALL a.clear() -- does not release unused array elements
LET a = getEmptyArray() -- releases the old array (and all of its elements)
...
FUNCTION getEmptyArray()
DEFINE r dynamic array of int
RETURN r
END FUNCTION
DYNAMIC ARRAY is a reference type, for that reason the "old" array will be released when assigning a "new" one. Be careful. If elements of the "old" array are still referenced, then the program crashes when dereferencing the elements.
BTW: the semantics of DICTIONARY elements when removing them from a DICTIONARY is much better. DICTIONARY elements will be released when removing *and* not being referenced.