[fpc-pascal] Memory leak on TFPGInterfacedObjectList
Joao Morais
l at joaomorais.com.br
Mon Jan 27 22:31:10 CET 2014
Hello list. Whenever I add interfaced objects to a
TFPGInterfacedObjectList, those objects apparently add two references,
while release only one when the list is cleaned or destroyed.
The following code shows:
==========>>>==========
$ /tmp/project1
just before vl.add(v1)..: 1
just after vl.add(v1)...: 3
after destroy the list..: 2
Heap dump by heaptrc unit
9 memory blocks allocated : 773/784
8 memory blocks freed : 757/768
1 unfreed memory blocks : 16
True heap size : 622592 (32 used in System startup)
True free heap : 622464
Should be : 622480
Call trace for block $000F31E0 size 16
$000210DF _P$PROJECT1_finalize_implicit, of
/private/tmp//tmp/project1.lpr
$00021EF1 _P$PROJECT1_finalize_implicit, of
/private/tmp//tmp/project1.lpr
$00020E4F _P$PROJECT1_finalize_implicit, of
/private/tmp//tmp/project1.lpr
==========<<<==========
The code:
==========>>>==========
program Project1;
uses
heaptrc, fgl, sysutils;
type
i1 = interface(iinterface)
function ref: integer;
end;
tl = specialize TFPGInterfacedObjectList<i1>;
t1 = class(TInterfacedObject, i1)
public
function ref: integer;
end;
var
v1: i1;
vl: tl;
function t1.ref: integer;
begin
result := frefcount;
end;
begin
v1 := t1.create;
vl := tl.create;
try
writeln('just before vl.add(v1)..: ', v1.ref);
vl.add(v1);
writeln('just after vl.add(v1)...: ', v1.ref);
vl.Clear;
finally
freeandnil(vl);
end;
writeln('after destroy the list..: ', v1.ref);
end.
==========<<<==========
Am I missing something?
Thanks!
More information about the fpc-pascal
mailing list