[Lazarus] TStringList.OwnsObjects bug?

Michael Van Canneyt michael at freepascal.org
Sun Feb 5 21:00:53 CET 2012



On Sun, 5 Feb 2012, Hans-Peter Diettrich 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 :-(

We do not copy code from Delphi. For one, because it's not allowed to copy 
and distribute copyrighted code.

Anyway; the bug is confirmed, and fixed in rev. 20265.

Michael.




More information about the Lazarus mailing list