How Do I Release COM objects?

Runtime Callable Wrapper is managed  hence its lifetime is controlled by Common Language Runtime. The COM component is freed from memory when the garbage collector calls the Finalize() method on RCW. Internally, RCW calls Release() of IUknown interface on the COM object.

To explicitly remove COM objects from memory, invoke the static method on Marshal class in System.Runtime.InteropServices namespace:

using System.Runtime.InteropServices;

Marshal.ReleaseComObject(myAuthorRCW);

No comments:

Popular Posts