CPropertySheet::RemovePage in MFC causes memory leak
-
Hi, In an application we've written we have a dialog based MFC application based on the CPropertySheet class. We are dynamically adding and removing pages while the the dialog is displayed. If the property pages we're adding and removing contain controls (i've tried it with buttons and treecontrols), then we have a memory leak: when I constantly add and remove pages, thus always returning to a same initial state, the application consumes more and more memory. It has nothing to do with the CPropertyPage derived objects themselves. I added several integer members to them, to make the memoryfootprint of the object bigger, but this doesn't cause the memory leak to be bigger. However, when I fill the dialog (by using the dialog editor of visual studio 6.0) with a lot of buttons, then the memory leak is getting bigger. I've added no functionality to the buttons, and not to the CPropertyPage derived class, except for one button with which I can add and remove pages to the CPropertySheet derived dailogbox. Thus it looks like MFC doesn't destroy the dialog template, or the controls on it. The page we're removing is NOT the active page. I've tried explicitly callling destroywindow on the propertypage that gets removed but this does not work neither. The only functionality the application has, is adding and removing CPropertyPage derived objects, so the memoryleak can not be caused by anything else. Does anyone have an idea what can be wrong and how to solve it :confused: Thanks, Serge Desmedt
-
Hi, In an application we've written we have a dialog based MFC application based on the CPropertySheet class. We are dynamically adding and removing pages while the the dialog is displayed. If the property pages we're adding and removing contain controls (i've tried it with buttons and treecontrols), then we have a memory leak: when I constantly add and remove pages, thus always returning to a same initial state, the application consumes more and more memory. It has nothing to do with the CPropertyPage derived objects themselves. I added several integer members to them, to make the memoryfootprint of the object bigger, but this doesn't cause the memory leak to be bigger. However, when I fill the dialog (by using the dialog editor of visual studio 6.0) with a lot of buttons, then the memory leak is getting bigger. I've added no functionality to the buttons, and not to the CPropertyPage derived class, except for one button with which I can add and remove pages to the CPropertySheet derived dailogbox. Thus it looks like MFC doesn't destroy the dialog template, or the controls on it. The page we're removing is NOT the active page. I've tried explicitly callling destroywindow on the propertypage that gets removed but this does not work neither. The only functionality the application has, is adding and removing CPropertyPage derived objects, so the memoryleak can not be caused by anything else. Does anyone have an idea what can be wrong and how to solve it :confused: Thanks, Serge Desmedt
Platform SDK documentation says that you shouldn't use PSM_REMOVEPAGE message (which is wrapped by CPropertySheet::RemovePage) during processing of some notifications: "A number of messages and one function call occur while the property sheet is manipulating the list of pages. While this action is taking place, attempting to modify the list of pages will have unpredictable results. Accordingly, you should not use the PSM_REMOVEPAGE message in your implementation of PropSheetPageProc or while handling the following notifications and Microsoft Windows messages: PSN_APPLY, PSN_KILLACTIVE, PSN_RESET, PSN_SETACTIVE, WM_DESTROY, WM_INITDIALOG" Tomasz Sowinski -- http://www.shooltz.com
-
Platform SDK documentation says that you shouldn't use PSM_REMOVEPAGE message (which is wrapped by CPropertySheet::RemovePage) during processing of some notifications: "A number of messages and one function call occur while the property sheet is manipulating the list of pages. While this action is taking place, attempting to modify the list of pages will have unpredictable results. Accordingly, you should not use the PSM_REMOVEPAGE message in your implementation of PropSheetPageProc or while handling the following notifications and Microsoft Windows messages: PSN_APPLY, PSN_KILLACTIVE, PSN_RESET, PSN_SETACTIVE, WM_DESTROY, WM_INITDIALOG" Tomasz Sowinski -- http://www.shooltz.com
I'm not doing anything of the above. On the propertypage derived classes there is a button, which sends a message to the propertysheet derived class, who then deletes a page which is not the current active page, and without changing the active page (so PSN_KILLACTIVE and PSN_RESET don't get send). Neither is the dialog startinh or closing, so none of the other meddages get send to the propertysheet. Serge Desmedt