[fpc-pascal] freeing string equal to setting to empty string?

David Emerson dle3ab at angelbase.com
Thu Jul 24 06:52:22 CEST 2008


On Wednesday 23 July 2008 7:46 pm, Marc Santhoff wrote:
> That's interesting and nice. Can I assume the same is valid for dyn
> arrays in a procedure or function context?

The short answer is yes.

There was recently (about a month ago) a discussion about some of these 
very issues, from 21 to 29 June. I'd encourage you to read it.

(Unfortunately I erroneously made the subject line "memory management 
with open arrays and classes"; and I replied to another thread instead 
of starting a new thread, so the messages don't appear in a nice little 
self-contained thread. doh!)

http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg12918.html

...and three messages following; make sure you read the one by Jonas, as 
the first reply contains some misinformation.

~David.


> 
> Normal vars do "behave" that way ...
> 
> program x;
> 
> procedure a;
> var
>   s: array of string;
> begin
>   SetLength(s, count);
>   s[0] := 'a string';
> 
>   ... do something ...
> 
> end; { no freeing of the array strings needed? }
Indeed not. Even if s was an array of ansistrings, they would still be 
cleaned up automatically when the var goes out of scope.
> 
> 
> Marc




More information about the fpc-pascal mailing list