title: deleting an array the wrong way
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1913343/how-could-pairing-new-with-delete-possibly-lead-to-memory-leak-only">How could pairing new[] with delete possibly lead to memory leak only?</a>  </p>
  </blockquote>
  
  
  
  <p>I was always told that it's not safe to call delete on an array allocated with new[]. You should always pair new with delete and new[] with delete[].</p>
  
  <p>So I was surprised to discover that the following code compiles and runs ok, in both Debug and Release mode under VS2008.</p>
  
  <pre><code>class CBlah
  {
  public:
      CBlah() : m_i(0) {}
  
  private:
      int m_i;
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      for(;;)
      {
          CBlah * p = new CBlah[1000]; // with []
          delete p;                    // no []
      }
      return 0;
  }
  </code></pre>
  
  <p>It took me a while to figure out why this works at all, and I think it's just luck and some undefined behaviour.</p>
  
  <p>BUT... it made me wonder... why doesn't Visual Studio pick this up, at least in the Debug memory manager? Is it because there's lots of code out there that makes this mistake and they don't want to break it, or do they feel it's not the job of the Debug memory manager to catch this kind of mistake?</p>
  
  <p>Any thoughts? Is this kind of misuse common?</p>