[Lazarus] TStringList.OwnsObjects bug?

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Feb 5 18:29:32 CET 2012


On Sun, 05 Feb 2012 18:16:21 +0100
Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:

> I wondered why my objects were not destroyed, and I think that I found 
> an bug in TStringList.Destroy:
> 
> destructor TStringList.Destroy;
> Var I : Longint;
> begin
>    FOnChange:=Nil;
>    FOnChanging:=Nil;
>    // This will force a dereference. Can be done better...
>    For I:=0 to FCount-1 do
>      FList^[I].FString:='';
>    FCount:=0;
>    SetCapacity(0); <-----------------------------
>    Inherited destroy;
> end;
> 
> I could not find anywhere instructions to free the objects, not in the 
> destructor nor in SetCapacity. Clear() destroys the owned objects, but 
> it cannot do anything after SetCapacity(0). IMO Clear() should be 
> called, instead of the attempts to clear the list in an more 
> efficient(?) way.
> 
> I suspect that the destructor was copied from Delphi, and was not 
> updated when OwnsObjects was added :-(
> 
> Before I file an bug report: Can somebody confirm this bug?

1. The word 'copied' is an insult of the FPC team.
2. TStringList is not part of Lazarus, it belongs to the FCL. Please ask
this question on the right list.

Mattias




More information about the Lazarus mailing list