I always pair my initialization of a dynamic array with a finalizer in the form of
finally
SetLength(Array, 0);
end;
It feels more natural to know exactly when the array gets "destroyed" and allows me smoother transition from arrays to TList if needed by already having a "finally" available.
Yet that approach makes the source code more indented. Is there any drawback in this approach - readability, maintainability, extensibility, performance, error prroness?
Sample code I write:
var
A1: array of Integer;
A2: array on Boolean;
A3: array of string;
begin
SetLength(A1, 10);
try
...
SetLength(A2, 20);
try
...
SetLength(A3, 30);
try
...
finally
SetLength(A3, 0);
end;
finally
SetLength(A2, 0);
end;
finnally
SetLength(A1, 0);
end;
end;