Dyn Arrays



Can I use SetLength to redimension a dynamic array.
For Instance can I do somthing like:

for I:= 1 to N do
begin
SetLength(MyArray, I);
Do Something with MyArray[I - 1];
end;

I am told that this leaks memory. Is that correct?

Thanks in advance.

alex.moore@xxxxxxxxxxx


.



Relevant Pages

  • Re: need to deallocate dynamic arrays (D4)
    ... SetLength(PretriggerBuffer, Pretrigger+1); ... To deallocate a dynamic array, assign nil to a variable that references the array or pass the variable to Finalize; either of these methods disposes of the array, provided there are no other references to it. ... I have other strings where I use SetLength, but they are temporary variables defined within procedures. ...
    (comp.lang.pascal.delphi.misc)
  • Re: dynamic Type declaration
    ... > SetLength ... > on a dynamic array? ... type tVariantArr = Array of Variant; ... ReadLn; ...
    (comp.lang.pascal.delphi.misc)
  • Re: dynamic Type declaration
    ... > SetLength ... > on a dynamic array? ... type tVariantArr = Array of Variant; ... ReadLn; ...
    (alt.comp.lang.borland-delphi)
  • Copying multidimensional dynamic arrays
    ... I've got an 3-Dimensional dynamic Array with the following ... Of course it would be initialised with SetLength. ... I've build an nested for-loop wich works well but not as fast ... for y:=1 to highy do ...
    (comp.lang.pascal.delphi.misc)
  • Dynamic arrays
    ... I was thinking I could SetLengtha dynamic array of 700, ... will still loop through 700 right. ... I know I could do another setlength() for each time an index is added, ... but doing that 200 times in a loop would seem awfully wasteful. ...
    (comp.lang.pascal.delphi.misc)