What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs:
The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object.
If I had to "guess" - this explanation should mean "one per process", but is it really? Any additional documentation will be very welcome.
My application runs in its own application domain (it is Outlook addin), and I would like to know what happens if I use Marshal.ReleaseComObject(x) in a loop until it's count reaches 0 (as recommended). Will it release references from other addins (running in other application domain in the same Outlook process)?
EDIT: Perfect - now the confusion is even bigger. Based on the 2 answers (from Lette and Ilya) we have 2 different answers. The official MSDN doc says per process (for ver. 2.0+), but it is missing this sentence for ver. 1.1 of the doc.
In the same time, in Mason Bendixen's article, it says it's per appdomain.
As his article is old (April 2007), I have send him an email asking for clarification, but if someone else has to add something, please do.
Thanks
The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to . NET clients, its primary function is to marshal calls between a . NET client and a COM object.
CCW - COM Callable Wrapper where the dlls which creted using . NET environment and using this COM to VB or other applications. RCW - Runtime Callable Warapper where the dlls created in any prior version of . net like VB6 and adding those DLLs to . NET environment using add reference and some other import options.
COM callable wrappers are invisible to other classes running within the . NET runtime. Their primary purpose is to marshal calls between managed and unmanaged code; however, CCWs also manage the object identity and object lifetime of the managed objects they wrap.
In managed, we have a per app domain cache mapping canonical IUnknowns back to RCWs. When an IUnknown enters the system (through a marshal call, through activation, as a return parameter from a method call, etc.), we check the cache to see if an RCW already exists for the COM object. If a mapping exists, a reference to the existing RCW is returned. Otherwise a new RCW is created and a cache mapping is added.
from Mason's Blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With