G
Guest
I have a question regarding garbage collection for threads. I am currently
developing on Visual Studio 2003 on .NET Framework 1.1. When I run this
simple app and watch the Handle count in Task Manager, the handle count keeps
increasing every time a new thread starts. If I uncomment the line
//GC.Collect();, handle count stabilizes after a moment.
Next I threw the same code onto VS2005 on .NET Framework 2.0, with
GC.Collect(); REM'ed out, the handle count also stabilizes after a moment,
but with GC.Collect(); the handle count stabilizes at a much lower count
compared to it being REM'ed out.
My questions are:
1. Is there a known issue with .NET 1.1 not able to garbage collect on
threads?
2. From the posts I read, GC should automatically kick in to do cleanup. So
then, should I manually perform a GC?
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
TestThread();
}
private void TestThread()
{
lbl_Time.Text = DateTime.Now.ToString();
gtTimerThread = new Thread(new ThreadStart(TimerThreadProc));
gtTimerThread.Start();
//GC.Collect();
}
private void TimerThreadProc()
{
Thread.Sleep(1000);
this.Invoke(gtdTestThread);
}
developing on Visual Studio 2003 on .NET Framework 1.1. When I run this
simple app and watch the Handle count in Task Manager, the handle count keeps
increasing every time a new thread starts. If I uncomment the line
//GC.Collect();, handle count stabilizes after a moment.
Next I threw the same code onto VS2005 on .NET Framework 2.0, with
GC.Collect(); REM'ed out, the handle count also stabilizes after a moment,
but with GC.Collect(); the handle count stabilizes at a much lower count
compared to it being REM'ed out.
My questions are:
1. Is there a known issue with .NET 1.1 not able to garbage collect on
threads?
2. From the posts I read, GC should automatically kick in to do cleanup. So
then, should I manually perform a GC?
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
TestThread();
}
private void TestThread()
{
lbl_Time.Text = DateTime.Now.ToString();
gtTimerThread = new Thread(new ThreadStart(TimerThreadProc));
gtTimerThread.Start();
//GC.Collect();
}
private void TimerThreadProc()
{
Thread.Sleep(1000);
this.Invoke(gtdTestThread);
}