When do I need to deallocate memory?

Posted by extintor on Stack Overflow See other posts from Stack Overflow or by extintor
Published on 2010-05-25T20:58:46Z Indexed on 2010/05/26 7:31 UTC
Read the original article Hit count: 256

Filed under:
|
|

I am using this code inside a class to make a webbrowser control visit a website:

void myClass::visitWeb(const char *url)
{
    WCHAR buffer[MAX_LEN];
    ZeroMemory(buffer, sizeof(buffer));
    MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, url, strlen(url), buffer, sizeof(buffer)-1);

    VARIANT vURL;
    vURL.vt = VT_BSTR;
    vURL.bstrVal = SysAllocString(buffer);

    // webbrowser navigate code...

    VariantClear(&vURL);
}

I call visitWeb from another void function that gets called on the handlemessage() for the app. Do I need to do some memory deallocation here?, I see vURL is being deallocated by VariantClear but should I deallocate memory for buffer? I've been told that in another bool I have in the same app I shouldn't deallocate anything because everything clear out when the bool return true/false, but what happens on this void?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++