[fpc-pascal] TInterfacedObject memory management

Juha Manninen (gmail) juha.manninen62 at gmail.com
Sun Oct 17 15:31:14 CEST 2010


Hi

I have a program that creates a TInterfacedObject and nothing else.

program project1;
{$mode objfpc}{$H+}
uses
  Classes;
var
  io: TInterfacedObject;
begin
  io := TInterfacedObject.Create;
end.
      
I compile it with -gh (heap trace) and get the following output:

[DBGTGT] Heap dump by heaptrc unit
[DBGTGT] 19 memory blocks allocated : 1191/1208
[DBGTGT] 18 memory blocks freed     : 1167/1184
[DBGTGT] 1 unfreed memory blocks : 24
[DBGTGT] True heap size : 393216
[DBGTGT] True free heap : 393024
[DBGTGT] Should be : 393064
[DBGTGT] Call trace for block $00007FFFF7FAE6C0 size 24
[DBGTGT]   $00000000004001F2 line 11 of project1.lpr
[DBGTGT]   $00000000004001B0

If I add "io.free" then there are no unfreed memory blocks.
Now, I have understood interfaced objects are reference counted and freed 
automatically. Is this a bug or did I understand it wrong?


Regards,
Juha



More information about the fpc-pascal mailing list