title: Memory leaks in my program; is the destructor not getting called?
body: <p>I feel like I'm bashing my head on a brick wall here.</p>
  
  <p>I'm not sure that the destructor is actually getting called. I'm using a priority_queue to hold a bunch of nodes. Each node has a member, m_grid, that is a 2D array of structs. This grid represents the only pointers I explicitly use in my program. </p>
  
  <p>For some reason, I'm getting lots of leaks. Could you help me out?</p>
  
  <p>Here's the destructor:</p>
  
  <pre><code>grid::~grid()
  {
    for (int i = 0; i &lt; m_width; i++)
    {
      delete[] m_grid[i];
      m_grid[i] = NULL;
    }
  
    delete[] m_grid;
    m_grid = NULL;
  }
  </code></pre>
  
  <p>The assignment operator:</p>
  
  <pre><code>grid&amp; grid::operator=(const grid&amp; g)
  {
    m_x_rad = g.m_x_rad;
    m_y_rad = g.m_y_rad;
    m_width = g.m_width;
    m_height = g.m_height;
    m_orientation = g.m_orientation;
  
    if (m_width != 0)
      m_grid = new cell* [m_width];
  
    // from left to right
    for (int i = 0; i &lt; m_width; i++)
    {
      m_grid[i] = new cell [m_height];
  
      // from top to bottom
      for (int j = 0; j &lt; m_height; j++)
      {
        m_grid[i][j].m_occupied = g.m_grid[i][j].m_occupied;
        m_grid[i][j].m_rad = g.m_grid[i][j].m_rad;
      }
    }
  
    return *this;
  }
  </code></pre>
  
  <p>The assignment operator is similar and as-expected.
  Finally, here's a bit of valgrind output (there's a lot, but it all concerns grid::setSize() or grid::operator=.</p>
  
  <pre><code>==13329== 200 (40 direct, 160 indirect) bytes in 1 blocks are definitely lost in loss record 25 of 166
  ==13329==    at 0x4C2E80F: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==13329==    by 0x4020C1: grid::operator=(grid const&amp;) (grid.cpp:192)
  ==13329==    by 0x40A02E: node::operator=(node const&amp;) (node.cpp:129)
  ==13329==    by 0x4075A6: __push_heap&lt;__gnu_cxx::__normal_iterator&lt;node*, std::vector&lt;node&gt; &gt;, long int, node, __gnu_cxx::__ops::_Iter_comp_val&lt;std::greater&lt;node&gt; &gt; &gt; (stl_heap.h:135)
  ==13329==    by 0x4075A6: push_heap&lt;__gnu_cxx::__normal_iterator&lt;node*, std::vector&lt;node&gt; &gt;, std::greater&lt;node&gt; &gt; (stl_heap.h:199)
  ==13329==    by 0x4075A6: push (stl_queue.h:502)
  ==13329==    by 0x4075A6: aStarGraphSearch(basic_map const&amp;, node&amp;, std::unordered_map&lt;int, basic_node, std::hash&lt;int&gt;, std::equal_to&lt;int&gt;, std::allocator&lt;std::pair&lt;int const, basic_node&gt; &gt; &gt;&amp;, std::priority_queue&lt;node, std::vector&lt;node, std::allocator&lt;node&gt; &gt;, std::greater&lt;node&gt; &gt;&amp;) (main_functions.cpp:216)
  ==13329==    by 0x4088ED: search(int) (main_functions.cpp:706)
  ==13329==    by 0x401AAA: main (main.cpp:13)
  </code></pre>
  
  <p>I'm really struggling here. I didn't have these issues when I was using stack instead of priority queue. Any help is appreciated.</p>