PC Review


Reply
Thread Tools Rate Thread

How do I release memory used by a user control?

 
 
Optimus
Guest
Posts: n/a
 
      25th Jul 2006

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();
}


ต*บกลับ

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to release memory used by a user control? Optimus Microsoft Dot NET Compact Framework 0 25th Jul 2006 07:47 AM
How do I release memory used by a user control? Optimus Microsoft Dot NET Compact Framework 0 23rd Jul 2006 03:50 PM
Re: Can Dispose() release memory used by controls? EggHead Microsoft Dot NET Framework Forms 1 25th Apr 2005 05:50 PM
How to release memory used by application Mullin Yu Microsoft C# .NET 3 9th Jun 2004 03:31 PM
Release Memory used by Webservice David Hanson Microsoft Dot NET Compact Framework 3 2nd Nov 2003 11:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:16 PM.