| | |
Delphi SetLength dilemma
![]() |
Hello,
does the SetLength function in Delphi called with the second argument 0 free the memory used for the array?
Example:
and if this doesn't work, how can I free memory for array...
Thanks
does the SetLength function in Delphi called with the second argument 0 free the memory used for the array?
Example:
Delphi Syntax (Toggle Plain Text)
var Names: array of String; i: Byte; SetLength(Names,10); for i:=0 to 9 do Names[i] := '...'; SetLength(Names,0); // << does this code free memory used by Names array ?
Thanks
All objects in Delphi, including 'string', are allocated on the heap. When you resize a dynamic array the unused objects are automatically destructed for built-in types only -- so in this case, yes.
When you set the length of a dynamic array to zero the dynamic array object itself is also freed and its value becomes nil.
However, deallocating an object does not necessarily mean that Delphi returns memory to the system.
Hope this helps.
When you set the length of a dynamic array to zero the dynamic array object itself is also freed and its value becomes nil.
However, deallocating an object does not necessarily mean that Delphi returns memory to the system.
Hope this helps.
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Integating Paradox table into MS-Excel 2007
- Next Thread: cxgrid Row Grouping
| Thread Tools | Search this Thread |






