Search code examples
c++visual-c++delete-operator

Should I call class destructor in this code?


I am using this sample to decode/encode some data I am retrieving/sending from/to a web server, and I want to use it like this:

BOOL HandleMessage(UINT uMsg,WPARAM wParam,LPARAM lParam,LRESULT* r)
{
  if(uMsg == WM_DESTROY)
  {
    PostQuitMessage(0);
    return TRUE;
  }
  else if(uMsg == WM_CREATE)
  {
    // Start timer
    StartTimer();
    return TRUE;
  }  
  else if(uMsg == WM_TIMER)
  {
    //get data from server
    char * test = "test data";
    Base64 base64;
    char *temp = base64.decode(test);
    MessageBox(TEXT(temp), 0, 0);
  }
}

The timer is set every 5 minutes.

Should I use delete base64 at the end? Does delete deallocates everything used by base64?


Solution

  • base64 is in local storage. It goes out of scope and is destructed at the end of the block. The only question left is ownership of temp. If its memory is owned by base64, then you do not need to delete anything.