Is there a way in .NET to determine the amount of memory being taken up by thread-local storage?
Specifically, I'm looking to find the amount of memory used by ThreadStatic objects and by memory allocated to objects in the Thread data slots (e.g. by calling Thread.SetData).
To clarify:
Thread-local storage: http://msdn.microsoft.com/en-us/library/6sby1byh.aspx
Thread Local Storage: Thread-Relative Static Fields and Data Slots http://msdn.microsoft.com/en-us/library/6sby1byh.aspx
You can get the memory usage by process as below. There are several other memory measurements that you can use here. But, I am not quite sure whether there is a way to get the memory usage by thread. Process has Threads property which consists of a collection of ProcessThreads which is exactly what you are interested in, but not straight forward way to get the memory usage.
// Get the current process.
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
// Gets the amount of physical memory allocated for the associated process.
long totalNumberOfBytesUsed = currentProcess.WorkingSet64;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With