Memory usage in VB.Net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JosR

    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 CloseTheSecondF orm()
    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.

  • Sylvain Lafontaine

    #2
    Re: Memory usage in VB.Net

    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:
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.


    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" <JosR@discussio ns.microsoft.co m> wrote in message
    news:928BB964-041E-45C6-9548-412C9A5FDCFD@mi crosoft.com...[color=blue]
    >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 CloseTheSecondF orm()
    > 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.
    >[/color]


    Comment

    • Chris Dunaway

      #3
      Re: Memory usage in VB.Net

      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.

      Comment

      Working...