views:

178

answers:

1

Hello,

I was profiling my .net windows service. I was trying to discover OutOfMemoryException and discovered that my stack size is huge and is growing because the the number of threads keeps growing.

Each thread gets 1024 KB on Windows x64 machine. Thus when my app has 754 threads the stack size would be 772 MB. The problem for me is that i don't know where these thread come from. Initially my app has a very limited number of threads and they keep growing with time.

I have two suspicions - either these threads are created by WCF or by database connection. My application uses both WCF and datasets. Also I tried to profile my app in Ants do Trace i can see large number of System.ServiceModel.Channels.ClientReliableDuplexSessionChannel and this number is increasing with time. I can see thousands of these objects created. So what I want to know is who is creating threads (tools to discover, profilers) and if it is WCF who is creating these threads.

UPDATE

I have stopped in debugger my app to look at the threads. All I can see a large number of Win32 threads with call stack like that

ntdll.dll!7c82860c()    
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!7c827d99()    
kernel32.dll!77e4e02f()     
mscorwks.dll!79e7c7a8()     
mscorwks.dll!79f943fe()     
mscorwks.dll!79f94237()     
mscorlib.ni.dll!792f5577()  
mscorlib.ni.dll!792e01c5()  
+3  A: 

You could look at the program using a debugger - then you can see what all those threads are doing (most of them probably have a very similar call stack).

Pent Ploompuu
Hi Pent, posted results. Look like I don't have symbols loaded.
Captain Comic
You're only debugging the unmanaged part of the application. When you attach to the process, select "Managed" as one of the code types to debug. And you can load the symbols for kernel32.dll, ntdll.dll, etc from Microsoft Symbol Servers.
Pent Ploompuu
Pent thank you very much for you indeed simple advice. I have discovered the problem. I have a home-grown workloadmanager class that is a bit like managed pool of threads. All my threads are timer fired events waiting on lock statements
Captain Comic