MEMORY LEAK......
-
Hi, I've developed an application in which I've 2 dialog boxes(not property sheets) and they are all modeless dialogs .By clicking a button in the dialog1 the user can move to dialog2 and he can also move back to dialog1 by clicking another button in dialog2. In dialog1 after the button is clicked i'm creating dialog2 overloading the "Create" function and the code for that is something like.... DestroyWindow(); //to destroy dialog1 d2=new dialog2; //d2 is apointer of class belongong to dialog1 d2->Create(IDD_DIALOG2,NULL); //dialog2 is created the problem here is, I'm not able to delete the pointer d2,because if i delete it within the destructor of class dialog1 then the dialog2 wont be visible .If i dont delete it it leads to a "MEMORY LEAK" .Same is the case with dialog2......... So I'd like to know which will be the right place to delete the pointer so that the dialogs are created properly and there wont be any memory leak.Anxiously waiting for a reply....thanks in advance. Rajeev
-
Hi, I've developed an application in which I've 2 dialog boxes(not property sheets) and they are all modeless dialogs .By clicking a button in the dialog1 the user can move to dialog2 and he can also move back to dialog1 by clicking another button in dialog2. In dialog1 after the button is clicked i'm creating dialog2 overloading the "Create" function and the code for that is something like.... DestroyWindow(); //to destroy dialog1 d2=new dialog2; //d2 is apointer of class belongong to dialog1 d2->Create(IDD_DIALOG2,NULL); //dialog2 is created the problem here is, I'm not able to delete the pointer d2,because if i delete it within the destructor of class dialog1 then the dialog2 wont be visible .If i dont delete it it leads to a "MEMORY LEAK" .Same is the case with dialog2......... So I'd like to know which will be the right place to delete the pointer so that the dialogs are created properly and there wont be any memory leak.Anxiously waiting for a reply....thanks in advance. Rajeev
You need a readily accessible instance of a third class that contains the pointers to both dialogs. Each dialog can call functions in this class to free the memory when the dialog is being destroyed.