Do I produce a handle-leak?

M

Manfred Braun

Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
N

Nicholas Paldino [.NET/C# MVP]

Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?
 
M

Manfred Braun

Hi Nicholas,

thanks for the interest and sorry for my inaccuracy .... I monitor this with
NT Taskmanager. I use .Net 1.1 and Windows 2000 SP4, en. Just to be sure, I
now went to Perfmon, selected the process and see the same result. The exe
runs since yesterday evening, started an unknown value [until I registered
the problem], then I started to write the numbers down, starting with a
value of 172 and now I am on about 437 .....

Best regards,
Manfred

Nicholas Paldino said:
Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Manfred Braun said:
Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
M

Manfred Braun

Hello,

additional info:I do not know, what TaskManager/Perfomon summarises as
handles .... But from my understanding of my code, nothing should increase
of a not short time.

Regards,
Manfred

Manfred Braun said:
Hi Nicholas,

thanks for the interest and sorry for my inaccuracy .... I monitor this with
NT Taskmanager. I use .Net 1.1 and Windows 2000 SP4, en. Just to be sure, I
now went to Perfmon, selected the process and see the same result. The exe
runs since yesterday evening, started an unknown value [until I registered
the problem], then I started to write the numbers down, starting with a
value of 172 and now I am on about 437 .....

Best regards,
Manfred

message news:%[email protected]...
Manfred,

Where did you montior this handle increase? Also, what is the type of
handle that you are seeing increasing?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Manfred Braun said:
Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
M

Manfred Braun

Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Willy Denoyette said:
Could you post the remaining of this program?

Willy.

Manfred Braun said:
Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
M

Manfred Braun

Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

Manfred Braun said:
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Willy Denoyette said:
Could you post the remaining of this program?

Willy.

Manfred Braun said:
Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
W

Willy Denoyette [MVP]

The handles you see are OS Event handles (associated with the timer events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version, not
100% sure though).

Willy.


Manfred Braun said:
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

Manfred Braun said:
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Willy Denoyette said:
Could you post the remaining of this program?

Willy.

Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located
in my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every 10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the handles
are increasing endless. Where is my fault? And what are these
handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
M

Manfred Braun

Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of
the Job class, a private class from the Test class, but this is very small.
Thank you for the explanation!
Best regards,
Manfred

Willy Denoyette said:
The handles you see are OS Event handles (associated with the timer events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version, not
100% sure though).

Willy.


Manfred Braun said:
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of 461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth, I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

Manfred Braun said:
Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Could you post the remaining of this program?

Willy.

Hi All,

I am writing a proggi, which should monitor some processes. While doing
this, I needed a test-program and wrote one, which does nothing else
than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I assume
this is a bug, but I do not understand, where this could be located
in
my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires
every
10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the
handles
are increasing endless. Where is my fault? And what are these
handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
W

Willy Denoyette [MVP]

Manfred,
Right, Hmmm ... let's see 12 bytes per instance, say the Gen0 threshold is
256 Kb, that means a collection per 22000 instances and one instance per 10
secs, makes a collection per 220000 secs ;-).


Willy.

Manfred Braun said:
Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of
the Job class, a private class from the Test class, but this is very
small.
Thank you for the explanation!
Best regards,
Manfred

Willy Denoyette said:
The handles you see are OS Event handles (associated with the timer events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time. As the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version,
not
100% sure though).

Willy.


Manfred Braun said:
Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the number of
handles is changinging from a footprint of about 361 up to a max of
461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth,
I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really understand my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Could you post the remaining of this program?

Willy.

Hi All,

I am writing a proggi, which should monitor some processes. While
doing
this, I needed a test-program and wrote one, which does nothing else
than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I
assume
this is a bug, but I do not understand, where this could be
located
in
my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every
10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the
handles
are increasing endless. Where is my fault? And what are these
handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
M

Manfred Braun

Willy,

ahh! In the meantime, I added the Workingset to Perfmon, but this shows a
nearly constant line [over the sort time of the last 90 mintes], which is
now explained by you !!!

Thanks a lot,
Manfred

Willy Denoyette said:
Manfred,
Right, Hmmm ... let's see 12 bytes per instance, say the Gen0 threshold is
256 Kb, that means a collection per 22000 instances and one instance per 10
secs, makes a collection per 220000 secs ;-).


Willy.

Manfred Braun said:
Hello Willy and All,

thanks a lot; But you've overseen, that I regularly create an instance of
the Job class, a private class from the Test class, but this is very
small.
Thank you for the explanation!
Best regards,
Manfred

Willy Denoyette said:
The handles you see are OS Event handles (associated with the timer events),
as your program doesn't create instances of managed classes there is no
memory consumption and the GC wont kick in for a long period of time.
As
the
Finalizer thread only runs after a GC run, the managed resource (the OS
handle) won't get collected in a timely fashion and the count increases
until the GC kicks in (every 12 minutes, depending on the CLR version,
not
100% sure though).

Willy.


Hello All,

after Nicholas came up with his question, I started Perfmon. Now, I see
the
Taskmanager is not a good compagnion for a deeper analyzis :-(

In perfmon, I am seeing a saw tooth, which means, currently, the
number
of
handles is changinging from a footprint of about 361 up to a max of
461.
I thing the GC collects handles over time. But my start was about 172.

How to interpret this results from perfmon? After I saw the saw tooth,
I
think, this is related to CLR and there is really no problem in my code -
that's what I tried to understand, because I think, I really
understand
my
code ;-)

I'll let Perfom running for a time now.

Thanks,
Manfred

Hi,

this proggi is very simple, was just created to see some small/large cpu
load over time. Here it is in full:

Thanks so far and
best regards,
Manfred
===
/*

Name: TP.cs
Author: mb
Created: 15.0.2005
Purpose: Sleep a time, use cpu, sleep
Compile csc /nologo /debug:full /t:exe /out:TP.exe TP.cs

*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Timers;



namespace Test
{


public class Test
{

private System.Timers.Timer timer;
int counter;


public static int Main(string[] args)
{
int rtc = 0;

if(args.Length != 0)
{
Test t = new Test();
t.Run(args);

Console.WriteLine("Press <enter> to exit.");
Console.ReadLine();
}
else
{
Console.WriteLine("Args !!! [P1=Interval{s}]");
rtc = 1;
}

return rtc;
}


private void Run(string[] args)
{
//Create the "Timer"

this.counter = 0;
this.timer = new System.Timers.Timer(Int32.Parse(args[0]) * 1000);
this.timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
this.timer.Enabled = true;
}


private void OnTimer(object sender, ElapsedEventArgs e)
{
Console.WriteLine("TP.OnTimer;Counter:{0}", this.counter);
int steps = 0;

this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}


private class Job
{
private int steps;

public Job(int steps)
{
this.steps = steps;
}

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}

}//class

}//class



}//namespace

===

Could you post the remaining of this program?

Willy.

Hi All,

I am writing a proggi, which should monitor some processes. While
doing
this, I needed a test-program and wrote one, which does nothing else
than
to
consume some cpu, sometimes more, sometimes less. As I monitored this
process for a time, I found the handles increasing without end. I
assume
this is a bug, but I do not understand, where this could be
located
in
my
simple app. The core is as follows:

private void OnTimer(object sender, ElapsedEventArgs e) //fires every
10
seconds
{
int steps = 0;
this.counter++;
this.counter = this.counter % 10;

if(this.counter == 4)
{
steps = 1000;
}
else
{
if(this.counter == 9)
{
steps = 10000000;
}
}

if(steps != 0)
{
Job j = new Job(steps);
ThreadStart ts = new ThreadStart(j.Run);
Thread t = new Thread(ts);
t.IsBackground = true;
t.Start();
}
}

private class Job
{
private int steps;

public Job(int steps)
{ this.steps = steps; }

public void Run()
{
Console.WriteLine("Job.Run;Steps:{0}", this.steps);

//Consume some cpu

for(int i = 0; i < this.steps;i++);
}
}//class

The number of threads is stable in this program [as I expect], the
handles
are increasing endless. Where is my fault? And what are these
handles?
Some help would really be very welcomed!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top