Is delete appropriate after a WM_CLOSE Message
Posted on 2006-04-07
I have some code that goes through some gyrations, but essentially, a dialog is created as the child of a MDI window using the new operator, and is ultimately closed with a WM_CLOSE message. Following that close message, I am using the delete operator.
Sometime, but not always, the code fails on the delete. The literature is not exactly clear on the subject, but there are some implications that a child window is deleted automatically. So I wonder if my problem is that sometimes the WM_CLOSE message arrives before the delete is called, and since the window is already deleted, the delete causes the error. At other times, the delete occurs before the WM_CLOSE message arrives, so there are no problems. Also, I should add that the immediate parent of the dialog is closing at the same time. So, once again, if the parent is closing, is it reasonable to assume that the child dialog is automatically deleted as part of that process.
I guess that my question is should I remove the delete, or will that just lead to memory leaks, etc. later.
Thanks for your time, Rick