15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Deallocating modeless dialog resources

Shaju Mathew -- shajum@hpptc51.rose.hp.com
Thursday, January 30, 1997

 
        Environment: Visual C++ 4.2-flat, NT 4.0
Hi guys,
        I've quite a few modeless dialogs(some tracked by my frame window,
others by my CWinApp), in my project, and I'm a bit apprehensive about my
handling of the associated memory management. Specifically, I've two qns:
        (1)Typically I override OnCancel() and PostNcDestroy() as shown
below:
void CWebBrowserDialog::OnCancel(void)
{
        DestroyWindow();
}


void CWebBrowserDialog::PostNcDestroy(void)
{
        delete(this);//do not make ANY MORE calls to this
        //CDialog::PostNcDestroy();
}
        On close observation I see that the my CWebBrowserDialog* still
always has a valid non-null address(even though these overrides have been
called), but my hwnd resources are released as  expected.
        To me this implies that I'm leaking memory resources.
I've tried other options like keeping static pointers to these modeless
dialogs, but even then I'd still be carrying around one object around
all the time!
        Qn: What's the best way to deal with modeless dialogs, and making
sure that all resources are deallocated every time I kill the dialog?
        
        (2)I see that many applications do not feature Minimize and Maximize
buttons for their modeless dialogs. Is this a Windows std? What about resizable
borders for such dialogs?
        Thank you all for your time
--
***********************************************************************
                              .---.         .---.
Shaju Mathew                 /" "  \  WWW  /  " "\    Off:(916)785-9018 
Performance Technology Lab  / / ""  \(*|*)/  "" \ \ 
WCSO Group R & D           //////   '. V .`   \\\\\\ Home:(916)722-4576
Hewlett-Packard Company   //// / // : """ : \\ \ \\\\
8000, Foothills Blvd     // /   /  /`.""" '\  \   \ \\Fax:(916)785-1264
MS 5723, Roseville      //          //.".\\          \\
CA 95747-5723        	     -------UU---UU-------
                                   '//|||\\`        Shaju_Mathew@hp.com
***********************************************************************



Jim Lawson Williams -- jimlw@mail.ccur.com.au
Monday, February 03, 1997

At 11:13 AM 30/01/97 PST, Shaju Mathew  wrote:
> 
>        Environment: Visual C++ 4.2-flat, NT 4.0
>Hi guys,
>        I've quite a few modeless dialogs(some tracked by my frame window,
>others by my CWinApp), in my project, and I'm a bit apprehensive about my
>handling of the associated memory management. Specifically, I've two qns:
>        (1)Typically I override OnCancel() and PostNcDestroy() as shown
>below:
>void CWebBrowserDialog::OnCancel(void)
>{
>        DestroyWindow();
>}
>
>
>void CWebBrowserDialog::PostNcDestroy(void)
>{
>        delete(this);//do not make ANY MORE calls to this
>        //CDialog::PostNcDestroy();
>}
>        On close observation I see that the my CWebBrowserDialog* still
>always has a valid non-null address(even though these overrides have been
>called), but my hwnd resources are released as  expected.
>        To me this implies that I'm leaking memory resources.

G'day!
I think you're attributing too much intelligence to the system. I can't see
code being generated to search all pointers in your code to zap everything
with a value of CWebBrowserDialog*.  If all you're using PstNcDestroy for is to
"delete(this)", then consider moving that delete to the owing object 
(Mainframe, or whatever), and NULLifying the pointer there.  You'll get a 
warning in Debug mode about PostNcDestroy not being called, but it's 
irrelevant unless you have some real cleanup to do in that routine.

>I've tried other options like keeping static pointers to these modeless
>dialogs, but even then I'd still be carrying around one object around
>all the time!
>        Qn: What's the best way to deal with modeless dialogs, and making
>sure that all resources are deallocated every time I kill the dialog?
>        
>        (2)I see that many applications do not feature Minimize and Maximize
>buttons for their modeless dialogs. Is this a Windows std?

For those built with the Dialog Editor you have an easy choice: a check-box 
controlling each under the "styles" property.  They're "off" by default.
Your decision.

>What about resizable borders for such dialogs?

Resizing dialogs is beyond the scope of my experience.  Given that there is no
apparent equivalent in the Dialog Editor styles, and that dialogs are built 
from templates, I wonder if this can be done.  What are you trying to achieve?

>        Thank you all for your time
>--
>***********************************************************************
>                              .---.         .---.
>Shaju Mathew                 /" "  \  WWW  /  " "\    Off:(916)785-9018 
>Performance Technology Lab  / / ""  \(*|*)/  "" \ \ 
>WCSO Group R & D           //////   '. V .`   \\\\\\ Home:(916)722-4576
>Hewlett-Packard Company   //// / // : """ : \\ \ \\\\
>8000, Foothills Blvd     // /   /  /`.""" '\  \   \ \\Fax:(916)785-1264
>MS 5723, Roseville      //          //.".\\          \\
>CA 95747-5723        	     -------UU---UU-------
>                                   '//|||\\`        Shaju_Mathew@hp.com
>***********************************************************************
>

Regards,
Jim LW


>From the BBC's "Barchester Chronicles":

    "I know that ultimately we are not supposed to understand.
    But I also know that we must try."

       -- the Reverend Septimus Harding, 
          tax-consultant, crypt-analyst, clog-dancer, C++ programmer




Mike Blaszczak -- mikeblas@nwlink.com
Tuesday, February 04, 1997

At 08:51 2/3/97 +1100, Jim Lawson Williams wrote:

>>What about resizable borders for such dialogs?
>
>Resizing dialogs is beyond the scope of my experience.  Given that there
is no
>apparent equivalent in the Dialog Editor styles, and that dialogs are built 
>from templates, I wonder if this can be done.  What are you trying to
achieve?

Look again: you can set the "Border:" dropdown to "Resizing".


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.




Peter Drayton -- peter@ten.net
Wednesday, February 05, 1997

I assume that by 'resizeable dialogs' you mean dialogs that be resized =
and have their controls reposition intelligently?? If so, check out a =
particularly good article in the latest Windows Tech Journal that =
details a class library that does exactly that. It also works with =
property sheets, property sheet views and form views. You can get it =
(free) from http://www.nanocorp.com/nsviews/Nanosoft.htm.

Peter





| Вернуться в корень Архива |