795cda60   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 01.11.2011 11:57, schrieb Shan:   
   > FieldValues = new vector();   
   >   
   >   
   > I have the above FieldValues in a class as private member. How should   
   > I deallocate the memory allocated by this vector. Also I am populating   
   > the vector with dynamically allocated. I want make sure that   
   > char* memory also deallocated when I destroy the instance of the   
   > class.   
      
   Use "delete FieldValues" to deallocate the vector. Before that, use the   
   deallocation on all contained pointers that matches their allocation.   
      
   This is the correct variant, but don't do that. Instead of manually   
   managing the memory, simply use a vector. Don't use pointers,   
   neither for the vector nor inside the vector, that way you can't make   
   any mistakes.   
      
   For advanced programmers, there is also the possibility to use so-called   
   smart pointers, which are classes that are used to manage such resources   
   in a correct way.   
      
   BTW: In case you have a Java background, forget about the way "new" is   
   used there. In C++, you rarely use "new" and even less often you use   
   "delete", exactly because they are error-prone.   
      
      
   Good luck!   
      
   Uli   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|