Partager via


C6283

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6283: <variable> is allocated with array new [], but deleted with scalar delete

This warning appears only in C++ code and indicates that the calling function has inconsistently allocated memory with the array new [] operator, but freed it with the scalar delete operator. This defect might cause leaks, memory corruptions, and, in situations where operators have been overridden, crashes. If memory is allocated with array new [], it should typically be freed with array delete[].

Example

The following code generates this warning:

void f( )  
{  
  char *str = new char[50];  
  // code ...  
  delete str;  
}  

To correct this warning, use the following code:

void f( )  
{  
  char *str = new char[50];  
  // code ...  
  delete[] str;  
}  

Warning C6283 only applies to arrays of primitive types such as, integers or characters. If elements of the array are objects of class type then warning C6278 is issued.

The use of new and delete have many pitfalls in terms of memory leaks and exceptions. To avoid these kinds of leaks and exception problems altogether, use the mechanisms that are provided by the C++ Standard Template Library (STL). These include shared_ptr, unique_ptr, and vector. For more information, see Smart Pointers and C++ Standard Library.