New,delete operator
-
Hi, I use the following coe in my applcation.and i found memory leak in that. MyFunction() { char *czval; czVal = new char[100]; memset(czVal,0,100); ..... ..... } But i failed to delete the memory allocated. I use delete [] czval in OnDestroy it shows thw error czVal undeclared identifier and also delete is used for pointer only. Whats my mistake. I use new operator in my local function where i have to delete that. And also i need tutorial for this new and delete.Because i have lot og memory leaks in my applicatin.I dont know the proper usage of new and delete operator.
Anu
-
Hi, I use the following coe in my applcation.and i found memory leak in that. MyFunction() { char *czval; czVal = new char[100]; memset(czVal,0,100); ..... ..... } But i failed to delete the memory allocated. I use delete [] czval in OnDestroy it shows thw error czVal undeclared identifier and also delete is used for pointer only. Whats my mistake. I use new operator in my local function where i have to delete that. And also i need tutorial for this new and delete.Because i have lot og memory leaks in my applicatin.I dont know the proper usage of new and delete operator.
Anu
Make
czval
to global. Usedelete[] czval
in destructor / OnDestroy. -
Make
czval
to global. Usedelete[] czval
in destructor / OnDestroy. -
I have doubt that when this OnDestroy() get called. Whether we can give breakpoint in OnDestroy() and check that. Because when i ahve breakpoint in OnDestroy in my view class,the control didnot go to the breakpoint. I dont know why?
Anu
When the application is exited,
CView::OnDestroy()
will be invoked. So u can place thedelete
statement there.