When you use a COM or COM+ from a .NET application and then you set the object reference to Nothing (or let it go out of scope), the object isn’t released immediately. The reason: your program communicates with the COM object through a Runtime Callable Wrapper (RCW) object, which is responsible for the real object’s lifetime, thus the object will be actually released only when the RCW is garbage collection, which might happen several minutes later or even only when the entire application is shut down.
In most cases this behavior is acceptable, but at times it may be essential that the COM object is explicitly released when the .NET application doesn’t need it any longer. You can do this by calling the ReleaseComObject static method of the Marshal class (in the System.Runtime.InteropServices namespace):
' Create the objectDim obj As New MyComObject()' Use it' ....' Explicitly release itSystem.Runtime.InteropServices.Marshal.ReleaseComObject(obj)obj = Nothing