Delete operator and Debug Assertion errors
I seem to be getting a debug assertion error (not compiler error, error pops up when I run the program) when using the delete operator on a dynamically allocated node of a linked list. I ran the debugger and I know that the node is a valid pointer. I think it might have something to do with the fact that I declare the list in a program but modify it in a function in a run-time linked DLL. Here''s the exact Debug assertion error:
Debug Assertion Failed!
Program: ...TESTAPP.EXE
File: dbgheap.c
Line: 1076
Expression: _pFirstBlock == pHead
I''m really stumped on this one, any ideas on why this is happening are welcome.
-------------------------------NeXe: NeHe DirectX-style. Follow the orange rabbit.
I don''t know if this will help but I get this kind of error if I try to delete memory that wasn''t allocated with new. If you''ve deleted it already, this could cause a problem. I don''t know much about run-time libraries but I can''t see that causing a problem.
Hope that helps.
Hope that helps.
when you delete something the pointer itself still points to the same memory location, so after deletes you should always set the pointer to null:
int* pInt = new int;
delete pInt;
pInt = NULL;
delete pInt; //ok - delete doesnt blow up if given a null pointer, it just quietly fails
so how is it allocated? more info please
int* pInt = new int;
delete pInt;
pInt = NULL;
delete pInt; //ok - delete doesnt blow up if given a null pointer, it just quietly fails
quote:
I get this kind of error if I try to delete memory that wasn''t allocated with new
so how is it allocated? more info please
You might try using free() on the memory. Also, like the others said, a pointer might still look like its valid even though its not. Make sure you set pointers to NULL when you delete them.
----------------------------------------
Who is this General Failure and why is he trying to read my hard disk?
ian@gdnmail.net
----------------------------------------
Who is this General Failure and why is he trying to read my hard disk?
ian@gdnmail.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement