Archived

This topic is now archived and is closed to further replies.

squicklid

'delete' Assertion Failures

Recommended Posts

I get an Assertion Failure when I try to delete a previously allocated with ''new'' array of structs. It isn''t being deleted twice or anything. What could cause this?

Share this post


Link to post
Share on other sites

void Menu::destroy()
{
if (!element) return;

delete element;
element = NULL;

numelements = 0;
}


[edited by - squicklid on April 22, 2004 11:10:31 PM]

Share this post


Link to post
Share on other sites
WHAT does the assert say? Exactly?
And, when you post deletion code, you also need to post allocation code.

Dollars to donuts you''re overwriting right before or right after the element. Thus, right after you allocate the element, you should set two data breakpoints in the debugger, one for the address right before element, and one for the address right after element; if you overwrite structures in the heap, these data breakpoints will show you where it happens.

Share this post


Link to post
Share on other sites
quote:
Original post by squicklid
Actually, putting the [] in after delete worked. But I don''t quite understand that.


There are two different types of new and delete operators. One set is new/delete and the other is new[]/delete[]. They must be matched. That''s all.

Share this post


Link to post
Share on other sites