Jump to content
  • Advertisement
Sign in to follow this  
shoez

deleting dynamic memory error

This topic is 2500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :(?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
the first line is called inside the constructor of my object and the deletion occurs inside the destructor of the object.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!