title: C++ std::vector of pointers deletion and segmentation faults
body: <p>I have a vector of pointers to a class. I need to call their destructors and free their memory. Since they are vector of pointers vector.clear() does not do the job.So I went on to do it manually like so :</p>
  
  <pre><code>void Population::clearPool(std::vector&lt;Chromosome*&gt; a,int size)
  {
      Chromosome* c;
      for(int j = 0 ;j &lt; size-1;j++)
      {
         c = a.back();
         a.pop_back();
         delete c;
         printf("  %d \n\r",j);
         c = NULL;
  
      }
  
  }
  </code></pre>
  
  <p>The printf in there is since I have a talking destructor to see in which Chromosome the segmentation fault happens. When clearPool() is called and say we got a size of 100, it can give a segmentation fault in any Chromosome between 0 and 100.</p>
  
  <p>I have no idea why this might be happening nor do I have a way to actually find what's wrong since while debugging with breakpoints all I see is that it happens in there at random chromosomes.</p>
  
  <p>I am using codeblocks IDE and the gdb debugger. The stack trace when the segmentation fault happens has 4 memory addresses and a function <code>wsncpy()</code>.</p>