I'm tracing a memory leak in a Delphi ported component and found that the culprit was a TInterfacedObject descendant that was not being freed.

I found that if i directly call Free or _Release the memory leak vanishes (Delphi code does not call these).

My question is: is TInterfacedObject descendants supposed to be freed automatically or should i call Free directly?

See attached example.

Using fpc 2.1.4 under win32 XP SP2.

Luiz
program interfaceleak2;

{$mode delphi}

uses
  Heaptrc, Windows, Activex, Classes, SysUtils;
  
type
  TVTDragManager = class(TInterfacedObject, IDropSource)
  public
    constructor Create(AOwner: TComponent); virtual;
    destructor Destroy; override;

    function GiveFeedback(Effect: Integer): HResult; stdcall;
    function QueryContinueDrag(EscapePressed: BOOL; KeyState: Integer): HResult; stdcall;
  end;
  
  
constructor TVTDragManager.Create(AOwner: TComponent);
begin
  inherited Create;
end;

destructor TVTDragManager.Destroy;
begin
  WriteLn('Destroy');
  inherited Destroy;
end;

function TVTDragManager.GiveFeedback(Effect: Integer): HResult;
begin

end;

function TVTDragManager.QueryContinueDrag(EscapePressed: BOOL; KeyState: Integer
  ): HResult;
begin

end;     
     
var
  Manager: TVTDragManager;
begin
  Manager := TVTDragManager.Create(nil);
  WriteLn('Start');
  //Manager.Free;
end.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to