Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory leak and dialog boxes.

Status
Not open for further replies.

AliAndAli

Programmer
Aug 3, 2002
27
0
0
US
I started a simple dialog based project. On the dialog, there is a push button that when pressed brings up another dialog. I use the task manger to watch the memory used by my program. I bring up the second dialog by pressing on the push button and then close it. After I repeat this for few times I see the memory increased by 4K. (I assume window allocates memory to the processes in 4K chunks, otherwise, I would have seen the increase in the memory usage any time I brought up and dismissed the second dialog). I use modal dialog, I use a non modal dialog and call DestroyWindow on it, but in all the cases memory leak is still there. Does anybody know what is going on?

Thanks
 
Something is not being deleted somewhere. I don't think that calling DestroyWindow() actually deletes the memory allocated for the dialog. Perhaps, you should be using 'delete' to delete the dialog if you used the 'new' keyword to create it in the free store.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Something is wrong somewhere?
Try making it again.
As far as deleted DialogBoxes is concerned,modal dialog boxes r deleted themselves when closed.
Modeless Dialog Boxes needs to be explicitly destroyed.
 
mathu, if the dialog (whatever kind) is created in the free store using the 'new' keyword - it still needs to be deleted with the 'delete' command to free up the memory:

[tt]CMyDialog* dlg = new CMyDialog; // create a dialog

dlg->DoModal(); // display it

delete dlg; // delete it!![/tt]

:)
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Thank you for the responses. The dialog I am creating is a member of the class ( so, it is created on the stack.)All I am doing is calling m_dlg.Create() rather than DoModal to make it Non modal. It appears to me that I should not call delete on this dialog. I wonder if there is any problem in creating a non-modal dialog this way rather than using the new operator.
 
Ali, it's all a question of scope. Other than that, there's not much difference except that you have to remember to 'delete' an object (at some point) that is created on the heap using the 'new' operator. I would suggest that you redeclare your dialog as a pointer and use the 'new' keyword to allocate it. Then, when you're through with it completely, 'delete' it and see what errors (if any) show up. If it deletes OK without problems then you may find that you no longer have a memory leak. If it does give you problems then it may help you to define where exactly the problem is.

:)
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top