•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 427,937 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,926 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 877 | Replies: 5
![]() |
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
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Integating Paradox table into MS-Excel 2007
- Next Thread: cxgrid Row Grouping



Linear Mode