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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
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:
    489
    David Hanson
    Nov 2, 2003
  2. Lloyd Dupont

    memory used by process ?

    Lloyd Dupont, Nov 12, 2003, in forum: Microsoft Dot NET Compact Framework
    Replies:
    1
    Views:
    229
    Brian Smith [MSFT]
    Nov 20, 2003
  3. 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,780
    Paul G. Tobey [eMVP]
    Dec 3, 2003
  4. 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:
    835
  5. Giorgos

    LocalFree Fails to Release Memory

    Giorgos, May 25, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    8
    Views:
    450
    Giorgos
    May 27, 2006
  6. arunmib

    memory once used not regained for application developed using dot net

    arunmib, Jun 6, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    1
    Views:
    219
    arunmib
    Jun 17, 2006
  7. 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:
    286
    Optimus
    Jul 23, 2006
  8. Optimus

    How to release memory used by a user control?

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