I have an automation object with event support that leaks memory. The FConnectionPoints which comes with the generated source is never freed. When I manually add FConnectionPoints.Free in the destructor, the leak goes away.
I am on Delphi 7, using a FastMM BorlandMM.dll and FastMM_Fulldebugmode.dll.
Steps to reproduce:
- Start a new ActiveX Library project
- Add a new Automation Object: Name = TestObject; Check "Generate Event support code"
- Open the TypeLibrary, add a method to ITestObject, add an event to ITestObjectEvents
- Refresh, code will be generated.
- Add ShareMem as the first unit in your .dpr file
- Save, compile and register this ActiveX Server (Run menu)
- Start a new Application project
- Put ShareMem as the first unit in your .dpr file
- Import Type Library unit: create the unit from the dll you've just created in step 6, and check "Generate Component Wrapper"
- In your FormCreate add the following code:
code:
var
lTest: TTestObject;
begin
lTest := TTestObject.Create(nil);
try
lTest.ConnectKind := ckNewInstance;
lTest.Connect;
lTest.Disconnect;
finally
lTest.Free;
end;
end;
Now compile, run and close this application. A memoryleak will be reported.
Question:
Is this a bug in the Delphi code template, am I doing someting wrong, or is it intended to free FConnectionPoints yourself (the help doesn't mention it)?
I found this issue to be reported in Quality Central report #1480.
A Sysop asked me to create a new report so I did: report #81288.
This also answers my question: it is a bug in the code template.