Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Do we have to free TStringList in DOTNET?

1 view
Skip to first unread message

Ralf Kaiser

unread,
Aug 3, 2005, 9:30:26 AM8/3/05
to
Hello,

the namespace Borland.VCL.Classes contains a class "TStringList".

Do i have to free instances of Borland.VCL.Classes.TStringList or are they
automatically destroyed when the go out of scope? (are they interfaces?)

TIA;
Ralf


Craig Stuntz [TeamB]

unread,
Aug 3, 2005, 10:31:12 AM8/3/05
to
Ralf Kaiser wrote:

> Do i have to free instances of Borland.VCL.Classes.TStringList or
> are they automatically destroyed when the go out of scope? (are they
> interfaces?)

All instances in .NET are freed when they go out of scope. But if a
class has an overridden destructor (I can't remember if TStringList
does in .NET, but you have the source, so go look) then you certainly
should call Free since that's how Delphi implements IDisposable.

--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Want to help make Delphi and InterBase better? Use QC!
http://qc.borland.com -- Vote for important issues

Ralf Kaiser

unread,
Aug 3, 2005, 2:27:35 PM8/3/05
to
"Craig Stuntz [TeamB]" <craig_...@nospam.please [a.k.a. acm.org]> schrieb
im Newsbeitrag news:42f0...@newsgroups.borland.com...

Hello,

> All instances in .NET are freed when they go out of scope. But if a

i was not sure if i remembered correctly :-)

> class has an overridden destructor (I can't remember if TStringList
> does in .NET, but you have the source, so go look) then you certainly
> should call Free since that's how Delphi implements IDisposable.

OK, thats good to know.

Thanks Craig,
Ralf

Marc Rohloff [TeamB]

unread,
Aug 3, 2005, 10:44:32 PM8/3/05
to
On Wed, 3 Aug 2005 15:30:26 +0200, Ralf Kaiser wrote:

> Do i have to free instances of Borland.VCL.Classes.TStringList or are they
> automatically destroyed when the go out of scope? (are they interfaces?)

They are automatically cleaned up by the GC. This may be at some time
much later than when they go out of scope.
The only reasonto force a Free on something like a TStringList is if
th Objects[] property contains references to objects which are
wrappers for unmanaged resources. (Window handles, file handles, etc)

--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com

0 new messages