A
alan
Dear all,
I have a problem on the caption subject.
I read many referece books, it remind me that if "new" is used, then
"delete" should be use to release memory.
Here is my testing problem.
char *func()
{
char *str = new char[10];
strcpy(str, "testing");
return str;
}
void main()
{
char *str = func();
cout<<str<<endl;
delete str; // <--------Error is prompted in here
}
When I used "delete" keyword, error message is prompted out.
If I do not use "delete" keyword, it works fine.
But I have a query, the allocated memory cannot be released. If I have
100 or 1000 or more allocated memory (same as this situtation), my
program memory demand will be very large?? is it true?
How can I solve it ? or How can I release it ? and How can I impove
the program?
Please help. I am a newbie in C++.
Thank you very much.
Alan
I have a problem on the caption subject.
I read many referece books, it remind me that if "new" is used, then
"delete" should be use to release memory.
Here is my testing problem.
char *func()
{
char *str = new char[10];
strcpy(str, "testing");
return str;
}
void main()
{
char *str = func();
cout<<str<<endl;
delete str; // <--------Error is prompted in here
}
When I used "delete" keyword, error message is prompted out.
If I do not use "delete" keyword, it works fine.
But I have a query, the allocated memory cannot be released. If I have
100 or 1000 or more allocated memory (same as this situtation), my
program memory demand will be very large?? is it true?
How can I solve it ? or How can I release it ? and How can I impove
the program?
Please help. I am a newbie in C++.
Thank you very much.
Alan