sData()
{
totalTime = time = aantal = 0;
name = NULL;
timer = NULL;
}
~sData()
{
delete name;
name = NULL;
delete timer;
timer = NULL;
}
}sData;
static sData *data = NULL;
void cProfiler::free()
{
delete []data;
data = NULL;
delete path;
path = NULL;
}
deleting pointers:debug assertion failed
Hi all,
When i delete pointers i get the following run-time error:
debug assertion failed!
file dbgdel.cpp
Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
this is my code:
Can someone explain me what i'm doing wrong?
thx in advance
[edited by - Freaker13 on May 2, 2003 6:48:57 AM]
You''re either
1) deleting something which wasn''t new''ed
2) deleting something which was allready delete''ed
1) deleting something which wasn''t new''ed
2) deleting something which was allready delete''ed
Seems like you''re deleting an uninitialized (or already deleted) pointer.
''path'' isn''t initialized in your code-snippet. Otherwise I can''t see anything wrong..
(and it isn''t strictly necessary to set pointers to NULL in a deconstructor, as the variables can''t be referenced afterwards anyway (unless they''re static))
Run the debugger and see exactly what variable is causing the error - it''s probably easier to find the error then..
''path'' isn''t initialized in your code-snippet. Otherwise I can''t see anything wrong..
(and it isn''t strictly necessary to set pointers to NULL in a deconstructor, as the variables can''t be referenced afterwards anyway (unless they''re static))
Run the debugger and see exactly what variable is causing the error - it''s probably easier to find the error then..
both pointers give the same error(data and path). they are not deleted and are initialised.
i''ve checked them on NULL pointers now. But i still get the same error.
void cProfiler::free()
{
if(data != NULL)
{
delete []data;
data = NULL;
}
if(path!= NULL)
{
delete path;
path = NULL;
}
}
void cProfiler::free()
{
if(data != NULL)
{
delete []data;
data = NULL;
}
if(path!= NULL)
{
delete path;
path = NULL;
}
}
I've found it:
with strings i didn't use the new keyword like
char* path;
path = "string";
So don't i have to delete those string pointers?
[edited by - Freaker13 on May 2, 2003 7:51:55 AM]
with strings i didn't use the new keyword like
char* path;
path = "string";
So don't i have to delete those string pointers?
[edited by - Freaker13 on May 2, 2003 7:51:55 AM]
No, you don''t.
Unless you use the new keyword, variables are located on the stack and it is not necessary (or correct) to delete them.
As a rule: one new -> one delete
Unless you use the new keyword, variables are located on the stack and it is not necessary (or correct) to delete them.
As a rule: one new -> one delete
I have had this and I memorized that it is virtually ALWAYS when you have a crap ass copy constructor and pass an object by value. Pass by const reference.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement