title: Deleting double pointer causes heap corruption
body: <p>I am using a double pointer but when I try to delete it it causes Heap Corruption: CRT detected that the application wrote to memory after end of heap. It "crashes" inside the destructor of the object:</p>
  
  <pre><code>Map::~Map()
  {
      for(int i = 0; i &lt; mTilesLength; i++)
          delete mTiles[i];
  
      delete[] mTiles;
  }
  </code></pre>
  
  <p>mTiles is declared something like this:</p>
  
  <pre><code>Tile **mTiles = NULL;
  mTiles = new Tile *[mTilesLength];
  
  for(int i = 0; i &lt; mTilesLength; i++)
      mTiles[i] = new Tile(...);
  </code></pre>
  
  <p>If notable mTiles is a object of "Tile" which inherits from a object "Sprite" all 3 destructors are set as virtual (map, tile, sprite), not sure if that makes any difference but seemed to work until now.</p>