Setting the array length to zero will destroy the array, which goes counter to your desire to "keep the array loaded." However, it will free the memory for all the records and their strings (for any strings whose reference count is 1 at the time).
If you just want to free the memory for the strings, but keep the record memory allocated (because you plan to allocate another set of records immediately afterward, and you don't want the waste of releasing and re-allocating the same memory), then you can clear just the string members, but there's no single library call to do it for you. Instead, you'll need to write a loop and clear each record's fields yourself.
for i := 0 to High(transactions) do begin
transactions[i].alias := '';
transactions[i].description := '';
end;
If there are lots of fields in the record that need clearing, then it might be more convenient to assign a default TTransaction
value to each element of the array. You can use the Default
function, or in older versions of Delphi you can declare a TTransaction
that has all its fields clear already:
const
ClearTransaction: TTransaction = (alias: ''; description: ''; creation: 0; count: 0);
for i := 0 to High(transactions) do
transactions[i] := ClearTransaction;
// or
transactions[i] := Default(TTransaction);
Finalize
actually change the value ofa
, though? I've always been under the impression it doesn't — that it frees the memory while leaving the original address of the dynamic array stored ina
, in anticipation of a subsequent call to eitherFree
orInitialize
. – Derm