471,349 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

Memory usage in VB.Net

I have a memory problem when running a VB.Net application.
The application uses a from frmMain from which another form can be opened:

Private Sub OpenTheNewForm()
dim frm as New frmSecondform
frm ShowDialog()
End Sub

At some point in time the second form is closed and the program returns to
the main form frmMain:

Private Sub CloseTheSecondForm()
Me.Close()
End Sub

When I look at the memory usage during execution of the program (using
Windows' Taskmanager) I see the memory usage increase with several Mb's as
soon as the second form is loaded. That is normal, I guess.
But when I close this form only a few Kb's of memory are released. Loading
the second form again increases the memory usage by several Mb's again. And
so on and so on.
After opening the second form a couple of times, the total memory used by
the program may have increased to as much as 150-200 Mb.

I'm sure that this is not how it is intended to be. But I haven't find a
solution yet. I have tried the Dispose-statement, to no effect.

What am I missing here? How do I release unused memory.
Please note, that I am rather a newbie. Thanks.

Jul 21 '05 #1
2 5633
Under the .NET Framework, the release of memory is not deterministic and is
done/controlled by the GC (Garbage Collector).

The following two parts article by Jeff Richter is a good introduction to
the GC of .NET:
http://msdn.microsoft.com/msdnmag/is...I/default.aspx

This article is a little outdated and make reference to some features of the
Beta 1.0 which don't exist anymore but the overall idea is still true.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
"JosR" <Jo**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
I have a memory problem when running a VB.Net application.
The application uses a from frmMain from which another form can be opened:

Private Sub OpenTheNewForm()
dim frm as New frmSecondform
frm ShowDialog()
End Sub

At some point in time the second form is closed and the program returns to
the main form frmMain:

Private Sub CloseTheSecondForm()
Me.Close()
End Sub

When I look at the memory usage during execution of the program (using
Windows' Taskmanager) I see the memory usage increase with several Mb's as
soon as the second form is loaded. That is normal, I guess.
But when I close this form only a few Kb's of memory are released. Loading
the second form again increases the memory usage by several Mb's again.
And
so on and so on.
After opening the second form a couple of times, the total memory used by
the program may have increased to as much as 150-200 Mb.

I'm sure that this is not how it is intended to be. But I haven't find a
solution yet. I have tried the Dispose-statement, to no effect.

What am I missing here? How do I release unused memory.
Please note, that I am rather a newbie. Thanks.

Jul 21 '05 #2
When you show a form using ShowDialog, after you close it, you must
also call it's dispose method. This is not true of a form shown by
just calling Show.

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by rbt | last post: by
2 posts views Thread by tomvr | last post: by
2 posts views Thread by Jarvis | last post: by
20 posts views Thread by Philip Carnstam | last post: by
13 posts views Thread by Ilias Lazaridis | last post: by
1 post views Thread by yzghan | last post: by
1 post views Thread by Jean-Paul Calderone | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.