By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,191 Members | 777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,191 IT Pros & Developers. It's quick & easy.

Char*

P: n/a
This may be a dumb question, but...

I have heard that if you declare a char* dynamically, you do not need
to delete it. For example:

{
char* temp = new char[100];

//Do stuff...

//Do you need to delete?
//delete [] temp;
}

Is this true? Will you not get a memory leak if you fail to delete[] a
char*?

Thanks.

Nov 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
tr*****@gmail.com wrote:
This may be a dumb question, but...

I have heard that if you declare a char* dynamically, you do not need
From whom? Just so we know who to ignore.

Everything you allocate with new has to be freed with delete.

--
Ian Collins.
Nov 4 '06 #2

P: n/a
tr*****@gmail.com wrote:
This may be a dumb question, but...

I have heard that if you declare a char* dynamically, you do not need
to delete it. For example:

{
char* temp = new char[100];

//Do stuff...

//Do you need to delete?
//delete [] temp;
}

Is this true? Will you not get a memory leak if you fail to delete[] a
char*?
You need to delete[] or else get a memory leak.
Well, in fact the OS will probably release the memory for you
after your program terminates, but you should delete[]
it anyway.

HTH,
- J.
Nov 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.