Do I need to shoot internal objects of a COM Interop object?

I have a managed class that uses COM, which 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 the COM-Interob DLL, I am wondering if I need free manually or if gc is smart enough to do this automatically if I call ReleaseObject ()

My class implements IDisposable, and I am doing the following atm:

Runtime.InteropServices.Marshal.ReleaseComObject(myobj)

Do I need to take care of releasing all the internal objects created by the COM object or not? And if I need it, does the order matter (first internal, then parent and parent, and then internal)?

+3
source share
2 answers

, . , Office Automation , , , Office, .

, COM-.

+1

COM . , . (myObj) , ( CreateInnerClass), COM , . myObj, .

+1

Source: https://habr.com/ru/post/1754187/


All Articles