My .NET 1.1 program allocates many Threads that loop making database calls
and other stuff.
Thread1 = new Thread(new ThreadStart(this.Thread1));
Thread1.Start();
Thread2 = new Thread(new ThreadStart(this.Thread2));
Thread2.Start();
while(true){
Thread.Sleep(1000);
}
How can I tell how much memory each Thread is consuming, and distinguish
which one is taking the most ?.
(I would like to create memory counters for perfmon)
thanks B.
Jon Skeet [C# MVP] - 26 Mar 2008 20:51 GMT
> My .NET 1.1 program allocates many Threads that loop making database calls
> and other stuff.
[quoted text clipped - 13 lines]
>
> (I would like to create memory counters for perfmon)
There's no real idea of the amount of memory a thread takes, beyond
what's on the stack. As far as .NET is concerned, the objects you're
creating on each thread are available to *all* threads, because they
all share the same heap.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jeroen Mostert - 26 Mar 2008 20:57 GMT
> My .NET 1.1 program allocates many Threads that loop making database calls
> and other stuff.
[quoted text clipped - 11 lines]
> How can I tell how much memory each Thread is consuming, and distinguish
> which one is taking the most ?.
Threads do not consume memory (aside from their stack, which is
constant-sized); processes consume memory. The whole point of threads is
that they share process state.
If your threads do have a sense of "ownership" of objects and you want to
keep track of which thread is allocating the most of these objects, you'll
have to keep track of that yourself when you create them.

Signature
J.
Willy Denoyette [MVP] - 26 Mar 2008 22:49 GMT
>> My .NET 1.1 program allocates many Threads that loop making database
>> calls and other stuff.
[quoted text clipped - 15 lines]
> constant-sized); processes consume memory. The whole point of threads is
> that they share process state.
Agreed, but keep in mind that CLR threads have their stack space set to
(comitted by the CLR) 1MB (4MB for 64 bit code threads) per default.
Creating a few hundred threads may bite you real hard ;-).
Willy.