Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Memory statistics for a thread in C#

I'd just like to ask if there's a way to get the memory statistics of a thread (i.e. Working Set, Private Memory, etc.). I know that we can obtain those for a Process, but my app needs to run a set of tests and for each test, I need to get the stats, especially the Peak Memory. Right now the only way I do this is run the app for each test and get the Peak Memory of the process.

Is there perhaps a way to get thread-level memory stats?

Thanks.

like image 239
raistdejesus Avatar asked Oct 15 '25 14:10

raistdejesus


2 Answers

Threads don't have memory statistics.

Heap memory is not associated with any single thread.
The information you're looking for does not make sense.

like image 101
SLaks Avatar answered Oct 18 '25 07:10

SLaks


As the other responders suggest, you cannot get memory stats on a by-thread basis. Your best bet would be to either:

  1. Run in app-domain and use App domain resource monitoring

  2. Run in separate process and use properties on : System.Diagnostics.Process (for the running process).

like image 27
dashton Avatar answered Oct 18 '25 08:10

dashton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!