[Lazarus] TStringList.OwnsObjects bug?

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sun Feb 5 18:16:21 CET 2012


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?

DoDi





More information about the Lazarus mailing list