[fpc-pascal] Delegate Interface class does not seem to be referenced counted

Tony Whyman tony.whyman at mccallumwhyman.com
Wed Aug 10 15:14:32 CEST 2016


On 10/08/16 13:57, Marcos Douglas wrote:
> Hi,
>
> See the "problem" bellow:
>
> TMyClass = class(TInterfacedObject, IMyInterface)
>     private
>       FMyInterface: TDelegateClass; <<< HERE >>>
>       property MyInterface: TDelegateClass
>         read FMyInterface implements IMyInterface;
>     public
>       constructor Create(obj: TDelegateClass);
>       destructor Destroy; override;
>     end;
>
> and...
Just trying some further variations:

with

   TMyClass = class(TInterfacedObject, IMyInterface)
    private
      FMyInterface: IMyInterface; // class type
      property MyInterface: IMyInterface
        read FMyInterface implements IMyInterface;
    public
      constructor Create(obj: TDelegateClass);
      destructor Destroy; override;
    end;

the output is:

Creating TDelegateClass
Creating TMyClass
Creating TDelegateClass
Destroying TDelegateClass

so it is actually worse with both interfaces left dangling

You get the same result with:

    TMyClass = class(TInterfacedObject, IMyInterface)
    private
      FMyInterface: IMyInterface; // class type
      property MyInterface: IMyInterface
        read FMyInterface implements IMyInterface;
    public
      constructor Create(obj: IMyInterface); << The change
      destructor Destroy; override;
    end;




More information about the fpc-pascal mailing list