Re: [fpc-pascal] TInterfacedObject memory management

2010-10-17 Thread Juha Manninen (gmail)
On Sunday 17 October 2010 15:01:37 Paul Ishenin wrote:
> Try the same but replace io type to IUnknown.

Thanks Marco and Paul. I should have known this one.

Regards,
Juha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TInterfacedObject memory management

2010-10-17 Thread Paul Ishenin

 17.10.2010 21:31, Juha Manninen (gmail) wrote:

program project1;
{$mode objfpc}{$H+}
uses
   Classes;
var
   io: TInterfacedObject;
begin
   io := TInterfacedObject.Create;
end.

Try the same but replace io type to IUnknown.

Best regards,
Paul Ishenin.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TInterfacedObject memory management

2010-10-17 Thread Marco van de Voort
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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal