Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On page 85 of Don Box book, Essenti

Status
Not open for further replies.

AliAndAli

Programmer
Aug 3, 2002
27
US
On page 85 of Don Box book, Essential COM, is a code like this:
STDMETHODIMP MyClass::UseIt(VARIANT var) {
VARIANT var2;
VariantInit(&var2);
VariantChangeType(&var2, &var, 0, VT_BSTR);
ustrcpy(m_szSomeDataMember, SAFEBSTR(V_BSTR(&var2)));
VariantClear(&var2);
}

I am wondering what happens if we do not call VariantClear? if VARIANT goes out of scope without calling this function, could it cause memory leak?

Thanks,
Ali
 
VariantClear will release any resources held by the VARIANT.
If it contains a VT_BSTR member it will call SysFreeString on the member, if it contains a VT_DISPATCH member it will call Release in the interface etc. If you don't call VariantClear indeed the VARIANT variable will go out of scope, but the data it might be pointing to will not be released.
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top