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

Marc Santhoff M.Santhoff at t-online.de
Thu Jul 24 04:46:54 CEST 2008


Am Mittwoch, den 23.07.2008, 17:10 -0300 schrieb Joao Morais:
> Luca Olivetti wrote:
> > El Wed, 23 Jul 2008 17:15:13 +0200
> > Marc Santhoff <M.Santhoff at t-online.de> escribió:
> > 
> >> That's the important part, I'm dealing with cleanly freeing strings
> >> when destroying objects.
> > 
> > I may be wrong but I think you don't need to do anything, when you free
> > a class the memory used by string fields is automagically freed
> > (either that or heaptrc is lying[*] when it says my programs aren't
> > leaking memory)
> 
> Yup. Ansi strings, refcounted interfaces and dyn arrays are 
> automagically freed when declared as class members and you destroy the 
> instance.

That's interesting and nice. Can I assume the same is valid for dyn
arrays in a procedure or function context?

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? }


Marc




More information about the fpc-pascal mailing list