Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

C6283

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[].

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.