Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

TStringList.OwnsObjects bug?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hans-Peter Diettrich

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

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 26 lines
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

Reply by email

Michael Van Canneyt
to Hans-Peter Diettrich: I wondered why my objects were not destroyed, and I think that I found an bug in…
Hans-Peter Diettrich wrote 23 lines
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.

Reply by email

Hans-Peter Diettrich
to Michael Van Canneyt
Show quoted text 5 lines
> 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.

I should have said "inspired by Delphi" ;-)

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

Thanks for the quick fix :-)

DoDi

Reply by email