deleting dynamic memory error

Started by
4 comments, last by Hodgman 12 years, 2 months ago
m_pszConsoleTitle = new wchar_t[chCount];


How come when i allocate thove above memory...and then try and deallocate it using

delete[] m_pszConsoleTitle;

i obtain an assert error :(?
Advertisement
We would need more code/context to see. And what is the assert?

It could be that someone else is illegally writing in/around that memory block, going outside its bound and corrupting the heap, so the delete/free function can't find a valid memory block header or something like that.
Insufficient information. You can get an assertion for a number of different reasons. Sometimes the full assertion message will help you find out what the problem could be. Some possibilities is that you've already deleted the pointer, a buffer overrun corrupting the allocated memory, a buffer overrun corrupting the pointer itself and so on.
I'm going with SiCrane on this one, considering just running something like

[source]
int size = 10;
wchar_t* blah = new wchar_t[size];
//....

delete[] blah;
[/source]

has no issues but if you try to delete it again you get an assertion error.
the first line is called inside the constructor of my object and the deletion occurs inside the destructor of the object.
You've probably made a copy of the object, and both the original and the copy are performing the same deletion, probably due to a rule-of-three violation.
You'll have to post some real code that reproduces the problem for us to tell you why you're getting that error.

This topic is closed to new replies.

Advertisement