Interfaces returned from functions are not properly released.
Original Reporter info from Mantis: mitov
-
Reporter name: Boian Mitov
Original Reporter info from Mantis: mitov
- Reporter name: Boian Mitov
Description:
If interface is returned by function it is not released until the calling function goes out of scope:
--------CODE-------
type ITest = interface
end;
type TTest = class(TInterfacedObject, ITest)
public
destructor Destroy(); override;
end;
destructor TTest.Destroy();
begin
inherited;
end;
function TestFunc() : TTest;
begin
Result := TTest.Create();
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Atest : ITest;
begin
Atest := TestFunc(); // Obtains interface
Atest := NIL; // The interface should be released, but is not. The destructor is not called.
//... Other Code
//... Other Code
end; // The interface is released here.
Mantis conversion info:
- Mantis ID: 11503
- Monitored by: » mitov (Boian Mitov)