I'm trying to pass an array of objects from my host Delphi to a .NET plugin. I have imported interfaces from my .NET plugin which I implement using THYFakeIDispatch, as suggested in this post:
It works well, but causes a memory leak in the host Delphi app.
First, I start by creating the objects derived from THYFakeIDispatch and adding them to a THYDispatchArray. Then I call the DispatchArrayAsSafeArray function (uHYInterfaceHelpers unit) which I then pass to a function of another plugin interface.
The problem seems to lie in that last part, as I believe it is creating more reference copies which never get released. I call SafeArrayDestroy (VarUtils unit) to release the references on the PVarArray. I removed the call to the plugin interface method and I get no memory leak. If I also remove the SafeArrayDestroy, then I get the same memory leak.
Here's what the code looks like:
dispatchArray := ListAsDispatchArray(AList);
safeArray := DispatchArrayAsSafeArray(dispatchArray);
FPluginInterface.SomeMethod(safeArray); // if I remove this call, no memory leak
SafeArrayDestroy(safeArray); // if I also remove this call, memory leak
Some more info:
- Delphi XE4
- VS 2015, .NET 4.5.2 project
- Hydra 4
Any help would be appreaciated.