I am instantiating a COM object from a VBA script in excel as defined in a C# dll. The C# class I instantiate has a finalizer that performs garbage collection, notably other MS Office objects it references, which I should see appear and disappear in the task manager. In fact, the unit tests demonstrate that an Office process appears when the dll is called, and goes away when it is finished.
When the dll is called from the VBA, I have noticed that the processes remain open after the VBA function ends, i.e. the object is notcleaned up after being called, which leads me to believe that VBA does not release the COM object.
My function looks something like this:
Function Raz(inp As String)
Dim o: Set o = CreateObject("foo.bar")
o.InputFields.FirstInput = inp
o.Update
Raz = o.OutputFields.FirstOutput
End Function
I have added the following line at the end of the function in order to resolve the issue:
set o = Nothing
However, the resources in my COM process remain after execution and completion of my VBA script. How do I garbage collect my COM objects from VBA without manually creating a dispose call?