#8 Linked objects not freed

open
nobody
5
2003-03-16
2003-03-16
ALu
No

Objects, that are linked to each other are not freed by
the "garbage collector". I know that this must be a
problem to the garbager and we can solve this by
unlinking our objects before the end, but in "normal"
Delphi environment we have no need to do so. Solutions
for DWS?

An example:

type TA = class;

type TA = class
i : Integer;
C : TA;
constructor Create;
destructor Destroy; override;
end;

var TA_cnt : Integer = 0;

constructor TA.Create;
begin
i := TA_cnt; Inc(TA_cnt,1);
println('TA.Create ' + IntToStr(i));
end;

destructor TA.Destroy;
begin
println('TA.Destroy ' + IntToStr(i));
inherited;
end;

var A : TA = TA.Create;
var B : TA = TA.Create;

A.C := B; // <--- without these two lines ...
B.C := A; // <--- ... the destructors are called

println('End');

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks