Cleaning up ActiveX Objects in Delphi — calling Free

When a Chilkat object is declared using “TChilkat*” such as TChilkatSFtp, and it is instantiated dynamically, then it must be explicitly freed (destroyed). The following code fragment demonstrates. If the Free method is not called, then object instances will accumulate in memory.

procedure TForm1.Button1Click(Sender: TObject);
var
sftp: TChilkatSFtp;
i: Integer;

begin

for i := 1 to 1000 do
  begin
    sftp := TChilkatSFtp.Create(Self);

    // ....

    sftp.Free();
  end;

end;

end.