GC, Should I care?

Discussion in 'Microsoft Dot NET' started by Chris Mayers, Apr 15, 2005.

  1. Chris Mayers

    Chris Mayers Guest

    Hi,

    I am trying to track a suspected memory leak in an application I'm writing
    and through repeated simplification of my project, I have found the
    following which is quite easily replicated should you be prepared to give me
    5 minutes of your time...

    Create a new C# (Probably the same in VB dotNET but I've not tried it)
    Windows application with 2 forms, the default form -Form1 and one other one.
    that has a bunch of controls on it (say 20 buttons, 20 labels and a
    DataGrid) - Form2.

    On the default form, add a button to display the second form with some code
    like:

    private void button1_Click(object sender, System.EventArgs e)
    {
    using (form2 formTwo = new form2())
    {
    form2.ShowDialog();
    }
    }

    also on Form1 add a label, and a timer that updates the label text as
    follows (updates every 5 seconds -Interval = 5000-):

    private void timer1_Tick(object sender, System.EventArgs e)
    {
    label1.Text = GC.GetTotalMemory(False);
    }

    and finally a button that forces a Garbage Collection:

    private button2_Click(object sender, System.EventArgs e)
    {
    GC.Collect();
    }

    OK, my question/query is this, if I repeatedly click the button to open the
    second form, then close the second form, click the button, close the form
    etc. about 20-30 times, the display of GetTotalMemory seems to keep going
    up, and even after forcing Garbage Collections, never seems to get fully
    reclaimed. Should I care? and if I should, what (if anything) can I do about
    it?

    I would really appreciate an answer from someone who understands these
    things...

    Thanks a lot,

    Chris.
     
    Chris Mayers, Apr 15, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Mayers

    GC, Should I care?

    Chris Mayers, Apr 15, 2005, in forum: Microsoft Dot NET
    Replies:
    8
    Views:
    143
    Guest
    Apr 17, 2005
  2. Guest
    Replies:
    1
    Views:
    264
    RobinS
    Mar 28, 2007
  3. Guest
    Replies:
    0
    Views:
    132
    =?Utf-8?B?UGVyc2VwaG9uZQ==?=
    Jul 29, 2007
  4. Martin

    Advanced Windows Care program

    Martin, Feb 10, 2008, in forum: Microsoft Dot NET
    Replies:
    3
    Views:
    202
    RobinS
    Feb 13, 2008
  5. bazzandjo

    Live One Care Restore

    bazzandjo, Mar 11, 2008, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    146
    RobinS
    Mar 11, 2008
Loading...

Share This Page