[fpc-pascal] TInterfacedObject memory management
Marco van de Voort
marcov at stack.nl
Sun Oct 17 13:37:55 CEST 2010
In our previous episode, Juha Manninen (gmail) said:
> I have a program that creates a TInterfacedObject and nothing else.
>
> program project1;
> {$mode objfpc}{$H+}
> uses
> Classes;
> var
io: IUnknown;
> begin
> io := TInterfacedObject.Create;
> end.
Try the above program.
> 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?
Yes you understood it wrong. The interface references are reference counted,
the object references don't suddenly become ref-counted.
It is a common trap though.
More information about the fpc-pascal
mailing list