Does _variant_t call AddRef()/Release() on contained IUnknowns/IDispatches? Or do you have to do AddRef() manually when you stick something into a variant and Release() on the old thing when you replace it with something else?
"Jason S" wrote in message news:1139082104.482280.18310@g47g2000cwa.googlegroups.com > Does _variant_t call AddRef()/Release() on contained > IUnknowns/IDispatches? Yes. > Or do you have to do AddRef() manually when you stick something into a > variant and Release() on the old thing when you replace it with > something else? No, unless you assign it directly to the data member. E.g. _variant_t var; IDispatch* p; var = p; // any previous content is released, the pointer is AddRef'ed var.pDispVal = p; // this bypasses _variant_t member functions and // does not manage resources properly. // Don't do this unless you are sure you know what you are doing and why. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
aha! So _variant_t overloads '=' and sets its type accordingly. I take it that AddRef()/Release() applies only if the _variant_t is a VT_DISPATCH or VT_UNKNOWN, and not if the _variant_t is a VT_ARRAY of VT_VARIANTs since those sub-VARIANTs are not _variant_t's themselves. Is this stuff well-documented anywhere? The MSDN online docs for VC++ (both 6.0 and the most recent) are decent for the _variant_t constructor but say nothing about the overloaded ='s effect on addref/release. >:( >:( >:( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/html/_pluslang__variant_t.3a3a._variant_t.asp http://msdn2.microsoft.com/wyc8836e.aspx
> Is this stuff well-documented anywhere? Just look at the source code. Brian
>Just look at the source code. Huh. I didn't realize the source *was* available (it's all inline in <comutil.h> ) Thanks. Usually I prefer to RTFM than to UTSL, because of cryptic subtleties or whatever... but in this case I have to admit that the source is pretty clear.