Thread memory consumption

B

Brian Stoop

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.
 
J

Jon Skeet [C# MVP]

Brian Stoop said:
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)

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.
 
J

Jeroen Mostert

Brian said:
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 ?.
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.
 
W

Willy Denoyette [MVP]

Jeroen Mostert said:
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.

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.
 

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