Multiple Forms – Memory Management Question

BrendanS

Member
Joined
Dec 9, 2006
Messages
8
Programming Experience
Beginner
Hi

I created an application that uses several forms. From the main form (fMain, which acts as a game lobby) you launch other forms (each child form is a simple game such as word search, classic memory etc)

When I observe the application's memory usage via Windows Task Manager/Process, there is an increase in memory usage when launching a child form from fMain (as would be expected).

What I do not understand is, when I close a child form, the memory usage does not drop. When I re-open the same child form, the memory usage further increases.

I have it set as such:

In a module:

Friend fMain as Form1
Friend f2 as Form2
-------------------
In fMain:

If f2 Is Nothing Then
Me.Hide()
f2 = New Form2
f2.Show()
End If
--------------------
In f2:

Button click event:
Me.Close()

f2 Closing event:
f2 = Nothing
fMain.Show()
-------------------
Any help would be greatly appreciated!

Thanks,

Brendan
 
The numbers you see in Windows Task Manager is memory allocations, not actual memory usage. The memory management (Garbage Collector) of .Net Framework works in mysterious ways, don't worry too much about it unless you run into problems or write horribly inefficient code or something like that. What is always said when people ask about this is to minimize the application window and now check the memory allocation numbers again. Doesn't look as it's anything wrong with your setup.
 
Thanks for the reply John.

That's a relief. I did notice the 'allocation' numbers when minimized, which at the time only confused me more!

Brendan
 
Back
Top