VSoftTechnologies/Delphi-Mocks — Issue #3: Memory Leak in TInterfaceProxy
Author: idealist5000
Created: 2012-02-08 06:26:40+00:00
State: open

To Reproduce:
Build Project with Fastmm
In code Make something like a
TMock.Create.Free;

Here is a Fix:
Index: Delphi.Mocks.InterfaceProxy.pas

--- Delphi.Mocks.InterfaceProxy.pas (Revision 10624)
+++ Delphi.Mocks.InterfaceProxy.pas (Revision 10625)
@@ -75,8 +75,8 @@
begin
inherited;
FVirtualInterface := TProxyVirtualInterface.Create(Self,TypeInfo(T),Self.DoInvoke);
- //remove reference created in this constructor, the virtual interface and proxy's lifetime are now the same.
- FVirtualInterface._Release;
+ //remove reference created in this constructor, the virtual interface and proxy's lifetime are now the same.
+ Self._Release;
end;

destructor TInterfaceProxy.Destroy;
@@ -132,11 +132,13 @@
function TInterfaceProxy.TProxyVirtualInterface._AddRef: Integer;
begin
result := FProxy._AddRef;
+ inherited;
end;

function TInterfaceProxy.TProxyVirtualInterface._Release: Integer;
begin
result := FProxy._Release;
+ inherited;
end;

end.