TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  OAL#007Checked automatically with code checker

This rule is Obsolete
Synopsis:Don't mix new and delete for array and non-array types
Severity Level:1
Category:Object Allocation


If you use "delete" on an array then only the first element will be deleted, thus creating a memory leak:

  void  foo() 
    char* myString;
    myString = new char[10];
    delete myString;   // Wrong: memory leak introduced	
    delete[] myString; // Right

The opposite could go wrong as well, i.e. applying "delete[]" to a non-array pointer:

  class X {   
    void  foo()
      X* x = new X();
      delete[] x; // What happens here?

This causes undefined behavior in C++.