C++ Dynamic Memory Allocation - char* -
i'm having problem understanding part of dynamic memory allocation in c++.
i know standard practice avoid memory leak:
double* pvalue = null; // pointer initialized null pvalue = new double; // request memory variable *pvalue = 29494.99; delete pvalue;
however, i've seen lots of source code , delete
never used there free memory:
char* text = "something";
so question simple: should use delete
every time no longer need char pointer (or other)? or there exceptions?
i've read alot , i'm getting more confused hope can me.
edit:
thank explanation. understand , can make changes source code without worrying!
you should delete
create new
, , nothing else.
char* text = "something";
this not create new
, shouldn't delete
it.
in fact, statement doesn't create anything (apart pointer) - sets text
point string created when program started.
Comments
Post a Comment