Search code examples
c++memory-managementdynamic-memory-allocation

Debug assertion failed: _BLOCK_TYPE_IS_VALID


in C++ on following code:

class Foo {
    vector<Foo*> otherFoos;
};

int _tmain(int argc, _TCHAR* argv[])
{
  Foo* data = new Foo[5];
  delete data;
}

I get this following error: enter image description here

I'm using Visual Studio 2013. I have no idea what is wrong with my code whatsoever.


Solution

  • You should write delete [] data;. delete for new, delete[] for new[].