title: Deallocation in C++ (Array of Vector of Pointers)
body: <p>Ok, so I am creating a Graph class, I am hoping to be able to run algorithms on and maybe add a gui to later on this summer when I have some free time. Right now I have an adjList that is implemented as an array of vectors (one for each vertex), each vector is a list of pointers representing edges going from each associated vertex to other vertices. It is declared as a protected member of my Graph class like so:</p>
  
  <pre><code>std::vector &lt;Node*&gt; *adjList;
  adjList = new std::vector&lt;Node*&gt;[V];
  </code></pre>
  
  <p>I have a side question. Now here I have an array (through a pointer) of vectors that hold pointers. If instead this was not an array, but rather a pointer to just a single vector of node pointers then I could call the constructor like so:</p>
  
  <pre><code>adjList = new std::vector&lt;Node*&gt;(10);
  </code></pre>
  
  <p>This would allow me to specify a default size for the dynamic array in the vector, but it seems I cannot call the constructor, or at least can't get the syntax right when I have an array.</p>
  
  <p>Now for my main concern. For each of these vectors in my pointer array I add a number of node pointers to each vector using a call to the new operator in my addVertex method. Now I need to make sure I handle deallocation of all this correctly. I believe I have an understanding of how this should work in C++, but I know pointers are tricky so I wanted to get someone to take a look before I go on adding lots to this code base. I couldn't find anything with a few searches that was quite like what I have. Here is my deallocation:</p>
  
  <pre><code>for(int i =0; i &lt; V; i++)
      for (unsigned int j = 0; j &lt; adjList[i].size(); j++)
          delete adjList[i][j];
  delete adjList;
  </code></pre>
  
  <p>Will this get free all of the memory. Also is there an easy way for me to verify this for sure, eg. to keep a count of how much memory has been allocated using new while I am debugging?</p>
  
  <p>[EDIT: Update w/ more info]</p>
  
  <p>Here is a <a href="http://books.google.com/books?id=NLngYyWFl_YC&amp;lpg=PA531&amp;ots=BxQrJH2kG9&amp;dq=breadth%20first%20search%20cormen&amp;pg=PA531#v=onepage&amp;q&amp;f=false" rel="nofollow">link</a> to Google Books showing one of the algorithms I am wanting to implement given in psuedocode. This version of breadth-first search operates on an adjacency list, (an array of lists of pointers). Pointers must be used because of the attributes that are assigned to each node using the adjacency list.</p>
  
  <p>I am wanting to retain these attributes from my BFS algorithm stored to with each node after it is ran. I know it is possible to do this in other ways, perhaps indexing nodes and using parallel arrays to store the attributes. But I wanted to have code that worked similar to this psuedo-code (for BFS in the link).</p>