[fpc-pascal] Basic question about TStringList

g.marcou at chimie.u-strasbg.fr g.marcou at chimie.u-strasbg.fr
Thu Mar 27 13:27:56 CET 2008


Hi,

thanks for your very clear answer. In fact this is chilling me as I am  
thinking to the huge amount of memory leaks that I certainly have in  
my developements...

This means that whenever the assignement operator ":=" is used with  
TStringLists, the recieving list shall never be created!

As a consequence I have another question. Suppose I have a function  
that returns a TStringList:

Myfunction(): TStringList;

I must have inside a line like:

Result:=TStringList.Create;

Let A be a TStringList, I have two ways to catch the result of my function:

A:=Myfunction();

or

A.Assign(Myfunction());

In the first case, if do A.Free, I release the memory allocated by the  
function. What's arriving in the second case? I can do A.Free, but  
does that action will also release the memory allocated by the function?

By the way, do you have some tricks to detect this kind of error?

Thanks again,
Gilles Marcou






More information about the fpc-pascal mailing list