GC question

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

    #1

    GC question

    I hope someone can answer this question for me. I have two forms. One form
    is an MDI form and the second form contains many controls, such as panel,
    list box, etc. When I open this second form I noticed the application memory
    usage. After closing this form, memory stays the same. I thought that after
    closing this second from memory usage would be redurced, but it doesn't. I
    tried all sort of methods, such as calling GC.Collect(), using destructor ~,
    but nothing seems to work Can someone show me an effective method of calling
    GC on demand?

    Thanks a bunch!


  • Christopher Kimbell

    #2
    Re: GC question

    As a general rule you shouldn't mess with the GC.
    The GC will collect memory when it thinks its necesary, this may be when a
    certain threshold has been reached or at intervals.

    Chris

    "mao" <mao.nuon@nanos tream.com> wrote in message
    news:OW4ZGSFYEH A.3972@TK2MSFTN GP12.phx.gbl...[color=blue]
    > I hope someone can answer this question for me. I have two forms. One[/color]
    form[color=blue]
    > is an MDI form and the second form contains many controls, such as panel,
    > list box, etc. When I open this second form I noticed the application[/color]
    memory[color=blue]
    > usage. After closing this form, memory stays the same. I thought that[/color]
    after[color=blue]
    > closing this second from memory usage would be redurced, but it doesn't. I
    > tried all sort of methods, such as calling GC.Collect(), using destructor[/color]
    ~,[color=blue]
    > but nothing seems to work Can someone show me an effective method of[/color]
    calling[color=blue]
    > GC on demand?
    >
    > Thanks a bunch!
    >
    >[/color]


    Comment

    • macqcyr

      #3
      RE: GC question

      I am currently having the same problem. The closing of the window and calling
      GC.Collect should work but for some reason the destructor of the MDI child
      form is not called (therefore it prevents its child controls of being
      destructed).

      If instead of opening the the child form as MDI you open it as a modal
      dialog its destructor gets then called. This makes me think there is a bug in
      System.Windows. Forms.

      "mao" wrote:
      [color=blue]
      > I hope someone can answer this question for me. I have two forms. One form
      > is an MDI form and the second form contains many controls, such as panel,
      > list box, etc. When I open this second form I noticed the application memory
      > usage. After closing this form, memory stays the same. I thought that after
      > closing this second from memory usage would be redurced, but it doesn't. I
      > tried all sort of methods, such as calling GC.Collect(), using destructor ~,
      > but nothing seems to work Can someone show me an effective method of calling
      > GC on demand?
      >
      > Thanks a bunch!
      >
      >
      >[/color]

      Comment

      • Rob Windsor [MVP]

        #4
        Re: GC question

        I don't know all the internal details but the amount of memory shown to be
        used by your app in Task Manager isn't really the amount being used, it's
        more like the amount of memory reserved. I think the concept is that if your
        app needed some memory for the second form it'll probably neeed that memory
        again sometime soon so it doesn't immediately give it back to windows.

        To see this effect create a new WinForms app with no controls and run it. If
        you check Task Manager you'll see it's taking up around 15 Mb (that's the
        number on my machine). Now minimize the app, you'll notice that Task Manager
        now reports that your app is using less than 1 Mb (about 880 Kb on my
        machine).

        For more details check out this blog post by Rick Strahl.


        Also, you should check out this blog post I made on garbage collection, it's
        one of the mosty misunderstood parts of the Common Language Runtime.



        --
        Rob Windsor [MVP-VB]
        G6 Consulting
        Toronto, Canada




        "macqcyr" <macqcyr@discus sions.microsoft .com> wrote in message
        news:DDC22577-4AF0-4010-AAEB-010E21DB8180@mi crosoft.com...[color=blue]
        > I am currently having the same problem. The closing of the window and[/color]
        calling[color=blue]
        > GC.Collect should work but for some reason the destructor of the MDI child
        > form is not called (therefore it prevents its child controls of being
        > destructed).
        >
        > If instead of opening the the child form as MDI you open it as a modal
        > dialog its destructor gets then called. This makes me think there is a bug[/color]
        in[color=blue]
        > System.Windows. Forms.
        >
        > "mao" wrote:
        >[color=green]
        > > I hope someone can answer this question for me. I have two forms. One[/color][/color]
        form[color=blue][color=green]
        > > is an MDI form and the second form contains many controls, such as[/color][/color]
        panel,[color=blue][color=green]
        > > list box, etc. When I open this second form I noticed the application[/color][/color]
        memory[color=blue][color=green]
        > > usage. After closing this form, memory stays the same. I thought that[/color][/color]
        after[color=blue][color=green]
        > > closing this second from memory usage would be redurced, but it doesn't.[/color][/color]
        I[color=blue][color=green]
        > > tried all sort of methods, such as calling GC.Collect(), using[/color][/color]
        destructor ~,[color=blue][color=green]
        > > but nothing seems to work Can someone show me an effective method of[/color][/color]
        calling[color=blue][color=green]
        > > GC on demand?
        > >
        > > Thanks a bunch!
        > >
        > >
        > >[/color][/color]


        Comment

        Working...