Kumaraswamy

I am creating a form in MFC application and drawing dynamic controls like textboxes, buttons, labels and frame within it. I open the form and close the form. While closing the form I have taken care to delete the child controls first and then the parent control by issuing delete <controlname>

The amount of memory taken to draw the screen is the not amount of memory decreasing when I close the form. I have seen for every control ie., button, textbox and label its respective base class's Destroywindow function returns 1 (which stands for successful destruction of window) but I still don't see the memory getting released when I observe using windows task manager.

Can someone help me regarding this.

Thanks in advance



Re: Visual C++ General memory problem

Yashmak

MFC has its owner pooled memory management framework.

Usually, when you destroy a control, the memory will be return to it's memory pool but not system.






Re: Visual C++ General memory problem

Kumaraswamy

I understand that MFC has its own pooled memory management but what I do not understand is why is the system memory usage going high and never coming down

Let me know how to destroy the controls like textbox, button and label other than only issuing delete <controlname>

Thanks in advance

-- Kumar





Re: Visual C++ General memory problem

Simple Samples

It is not necessary to delete the controls explicitly; Windows does that for us. In MFC, the concept of a control is a little more vague. The C++ object is not the same thing as the Windows object. If you allocated the MFC class using new then of course you need to delete the object. The Windows control will be deleted (destroyed) either when the form is destroyed or when the C++ object is deteted.






Re: Visual C++ General memory problem

Simple Samples

In case it helps, a common technique is to show/hide a window instead of creating and destroying it many times.




Re: Visual C++ General memory problem

Kumaraswamy

i am creating controls like textbox, combobox and labels using new command on the class which I respectively derived from CEdit, CComboBox and CStatic and while closing of the screen I am deleting these controls using delete <controlname>. Now can someone tell me why is the memory as seen by the OS not coming down as it went up while drawing the screen. Hiding and showing screens will not help in my application as there will be around 30 to 40 screens all having more than 30 to 40 controls in each screen and my application is a MDI application so that the user can keep the screen open and go to some other screen.

I also know that the memory is given to these controls from heap can someone suggest how to free the memory from the heap. I also notice that the destructor of each derived class is being called when I issue delete command. Also the screens destructor is called and even its parents like Document class's and childframe's destructors are called.

Inspite of this the memory on the OS is not coming down and if all the screens are opened (20 to 30 screens) and then all are closed I can see around 50 to 60 MB of memory going high during opening of screen and during closing of screen only some 3 to 4 MB of memory is coming down.

Thanks in advance. With these inputs of mine suggest me how to release memory consumed back to OS during closure of screen





Re: Visual C++ General memory problem

Simple Samples

Unless there is something else besides "memory as seen by the OS" that is a problem, such as a memory leak or an error message or if there is something inhibiting execution of your program or another program, then you arre probably overreacting. Use of memory by Windows is complicated. There could be a valid explanation. So unless there is something such as a memory leak or an error message, your question is a Windows question that is outside the scope of these forums.