Re: Do I produce a handle-leak?



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" <aa@xxxxx> wrote in message
news:OowfeHdbFHA.3144@xxxxxxxxxxxxxxxxxxxxxxx
> 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 [MVP]" <willy.denoyette@xxxxxxxxxx> wrote in message
> news:ecLYdEdbFHA.2756@xxxxxxxxxxxxxxxxxxxxxxx
> > Could you post the remaining of this program?
> >
> > Willy.
> >
> > "Manfred Braun" <aa@xxxxx> wrote in message
> > news:upW$T1cbFHA.2128@xxxxxxxxxxxxxxxxxxxxxxx
> > > 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:_manfred.braun_@xxxxxxxxxxxx
> > > (Remove the anti-spam-underscore to mail me!)
> > >
> > >
> >
> >
>
>


.



Relevant Pages

  • Re: This program is not thread safe and cause run time error in debug mode
    ... As I have written this error appear only in debug mode and not in release ... private void start_Click ... private void RefreshTime(int hh, int mm, int ss) ...
    (microsoft.public.dotnet.languages.csharp)
  • Adding week to user control.
    ... private void InitializeComponent() ... public int Row; ... private SolidBrush m_sbBack = new SolidBrush; ...
    (microsoft.public.dotnet.languages.csharp)
  • This program is not thread safe and cause run time error in debug mode
    ... partial class Form1: Form ... private void start_Click ... private void RefreshTime(int hh, int mm, int ss) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to resize child window?
    ... this does not change the focus of any window. ... > private System.Windows.Forms.CheckBox checkBoxParent; ... > private void InitializeComponent() ... > int FindWindow; ...
    (microsoft.public.win32.programmer.gdi)
  • poker odds
    ... public static final int HIGH_CARD = 0; ... private static Logger logger; ... public Poker(int numCard, Card deck) ... public void maxSimulation ...
    (comp.lang.java.programmer)