title: Memory leak when read from file
body: <p>I'm trying to read data from XML file and store every element ("&lt; some data/>") in vector container  <code>vector&lt;TCHAR*&gt;</code> , why the Task Manager shows the memory usage much greater than vector size(~80mb instead of ~59mb) :</p>
  
  <pre><code>#define _UNICODE
  
  #include&lt;tchar.h&gt;
  #include&lt;iostream&gt;
  #include&lt;windows.h&gt;
  #include&lt;vector&gt;
  
  using namespace std;
  
  HANDLE hFile;
  HANDLE hThread;
  vector&lt;TCHAR*&gt; tokens;
  DWORD tokensSize;
  
  DWORD WINAPI Thread(LPVOID lpVoid);
  
  
  void main()
  {   
      tokensSize = 0;
      hFile = CreateFile("db.xml",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
      if(hFile == INVALID_HANDLE_VALUE)   {
          cout&lt;&lt;"CreateFile Error # "&lt;&lt;GetLastError()&lt;&lt;endl;      
      }
  
      DWORD fileSize = GetFileSize(hFile,NULL);
      cout&lt;&lt;"fileSize = "&lt;&lt;fileSize&lt;&lt;" bytes = "&lt;&lt;fileSize/1024/1024&lt;&lt;" mb"&lt;&lt;endl;
      TCHAR* buffer = new TCHAR[fileSize / sizeof(TCHAR) + 1];
      ZeroMemory(buffer,fileSize);
  
      DWORD bytesRead;
      if(!ReadFile(hFile,buffer,fileSize,&amp;bytesRead,NULL)){
          cout&lt;&lt;"ReadFile Error # "&lt;&lt;GetLastError()&lt;&lt;endl;        
      }
      CloseHandle(hFile);
  
      hThread = CreateThread(NULL,0,Thread,(LPVOID)buffer,0,NULL);    
  
      WaitForSingleObject(hThread,INFINITE);
  
      for(int i=0;i&lt;tokens.size();i++)
              tokensSize+=(_tcslen(tokens[i])+1)*sizeof(TCHAR);
      cout&lt;&lt;"vector size = "&lt;&lt;tokensSize&lt;&lt;" bytes = "&lt;&lt;tokensSize/1024/1024&lt;&lt;" mb"&lt;&lt;endl;
      cin.get();  
  }
  
  DWORD WINAPI Thread(LPVOID lpVoid)
  {
      wstring entireDB = (TCHAR*)lpVoid;
      delete[]lpVoid; 
  
      wstring currentElement;
      wstring::size_type lastPos = 0;
      wstring::size_type next;
  
      next = entireDB.find(_T("&gt;"),lastPos);
      TCHAR* szStr;
      do
      {               
          currentElement = entireDB.substr(lastPos,next+1-lastPos);
          szStr = new TCHAR[currentElement.length()+1];
          _tcscpy(szStr,currentElement.c_str());
          tokens.push_back(szStr);
          lastPos = next+1;
          next = entireDB.find(_T("&gt;"),lastPos);
      }
      while(next != wstring::npos);
  
      entireDB.clear();
      return 0;
  }
  </code></pre>
  
  <p>OUTPUT:~
  fileSize = 57mb
  vectorSize = 58mb</p>
  
  <p>but the TaskManager shows ~ 81mb.
  What am I doing wrong?
  THNX!</p>