Archived

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

Freaker13

deleting pointers:debug assertion failed

Recommended Posts

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:
      
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;
}
    
Can someone explain me what i'm doing wrong? thx in advance [edited by - Freaker13 on May 2, 2003 6:48:57 AM]

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
both pointers give the same error(data and path). they are not deleted and are initialised.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites