How do I release memory used by a user control?

Discussion in 'Microsoft Dot NET Compact Framework' started by Optimus, Jul 25, 2006.

  1. Optimus

    Optimus Guest

    How do I release memory used by a user control?
    I've written the code as follows.
    When dispose() method get called, the user control doesn't get
    destroyed and stay
    in memory even after garbage collection.

    In addition, I don't want to close the form so that another user
    control can be subsequently loaded
    into the form.


    Here's my code snippet:


    private void button4_Click(object sender, EventArgs e)
    {
    foreach (Control ctl in this.Controls)
    {
    if (ctl.Name == "UserControl1")
    {
    Control ctl1 = ctl;
    this.Controls.Remove(ctl1);
    ctl1.Dispose();
    ctl1 = null;
    }
    if (ctl.Name == "UserControl2")
    {
    Control ctl2 = ctl;
    this.Controls.Remove(ctl2);
    ctl2.Dispose();
    ctl2 = null;
    }
    }


    GC.Collect();
    GC.WaitForPendingFinalizers();
    }


    ตอบà¸à¸¥à¸±à¸š
     
    Optimus, Jul 25, 2006
    #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. David Hanson

    Release Memory used by Webservice

    David Hanson, Oct 25, 2003, in forum: Microsoft Dot NET Compact Framework
    Replies:
    3
    Views:
    287
    David Hanson
    Nov 2, 2003
  2. sheng shan

    how to unload a dll to release memory in vb.net with cf?

    sheng shan, Nov 26, 2003, in forum: Microsoft Dot NET Compact Framework
    Replies:
    8
    Views:
    2,194
    Paul G. Tobey [eMVP]
    Dec 3, 2003
  3. MS

    GC does not release unused memory to the system in WinCE 4.2

    MS, Apr 20, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    7
    Views:
    636
  4. Optimus

    How do I release memory used by a user control?

    Optimus, Jul 23, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    0
    Views:
    213
    Optimus
    Jul 23, 2006
  5. Optimus

    How to release memory used by a user control?

    Optimus, Jul 25, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    0
    Views:
    348
    Optimus
    Jul 25, 2006
Loading...

Share This Page