I have a managed class that uses a COM that looks like this.
Public Class MyClass
Private myobj as SomeComObject
Public Sub New()
myobj = CreateObject("SomeComObject.Class")
End Sub
Public Sub DoSomething()
dim innerobj as SomComObject.InnerClass
innerobj = myobj.CreateInnerClass("arg1", true, 5)
innerobj.DoSomething()
End Sub
End Class
Since I am using an unmanaged dll through a COM-Interob dll I am wondering if I need free the innerobj manually or if the gc is smart enough to do it automagically if I call ReleaseObject()
My class implements IDisposable and I do the following atm:
Runtime.InteropServices.Marshal.ReleaseComObject(myobj)
Do I need to take care of releasing all inner objects that are created by the COM Object or not? And If I do have to do it, does the order matter (first inner then parent vs parent then inner)?
I'm fairly certain that you should release them all separately. At least when using Office Automation it's a common reason for things to get stuck in memory when you don't release all the inner objects which is very easy to do in Office where there are so many collections.
I'd assume that it would be the same for other COM objects.