title: Proper destruction of pointers to objects
body: <p>I would like to ask a couple of quick questions about the proper destruction of int pointers and vector pointers. First, I have seen people ask in the past about these type of problems, and almost always there are several responses about how using vector pointers , pointers to objects ,etc in C++ is not good standard c++ coding practice, and that you should instantiate a copy of the object. That may be true, but you do not always have control of paradigms that have been layed before your arrival. The paradigm I am required to work in requires initializing pointers to almost everything. A very Java like approach to C++. One of the main reasons we do this is our data sets are so large , stack allocations would be subject to overflows.</p>
  
  <p>My questions:</p>
  
  <p>If I have a pointer to a int32_t array, what is the proper way to destroy it in the destructor?</p>
  
  <p>Note: Our practice is to set any pointer to NULL in the constructor. </p>
  
  <pre><code>I initialize it as a member variable. 
  int32_t *myArray_;
  
  When I use it in a method, I would:
  this-&gt;myArray = new int32_t[50];
  
  To delete it in the method I would call delete on the array:
  delete [] this-&gt;myArray;
  
  What is the proper call in the destructor?
  ~MyDestructor(){
  
      delete this-&gt;myArray_;
      or delete [] this-&gt;myArray_;
  
  }
  </code></pre>
  
  <p>I have the same question about vector pointers:</p>
  
  <pre><code>I initialize it as a member variable. 
  std::vector&lt;MyObject*&gt; *myVector_;
  
  When I use it in a method, I would:
  this-&gt;myVector_ = new std::vector&lt;MyObject*&gt;();
  
  
  //pushback some objects
  
  To delete the vector in the method I would iterate the vector and delete its objects, then    delete the vector;
  
   for(std::vector&lt;MyObject*&gt;::iterator itr = this-&gt;myVector_-&gt;begin(); 
   its != this-&gt;myVector-&gt;end(); ++ itr){
  
        delete (*itr);
  
  }
  
  delete this-&gt;myVector_;
  
  
  What would be the proper way to clean it up in the destructor?
  would I just delete the vector?
  
  delete this-&gt;myVector;
  
  or do I need to iterate the entire vector again?
  </code></pre>
  
  <p>Thanks in advance for any advice.</p>