0

The Visual Studio diagnostic tool can report memory usage by object, but I want my application to log this to file programmatically. I also want a breakdown of memory usage by thread. Is this possible?

Markus
  • 1,020
  • 14
  • 18
  • See this answer: https://stackoverflow.com/a/52602456/809357 this is for C, but that can shed some light on your question – trailmax Apr 06 '20 at 10:42
  • I know that threads share the same address space, but it may be within the .NET framework's power to report on which thread created each object that is still in memory. Even without the thread info, I'd like to know how to log it programmatically. – Markus Apr 06 '20 at 10:44
  • 1
    There is no built-in affinity to the thread that created an object in the heap. The class should implement this itself if it is needed, which is true from some types (which should execute code in a synchronization context). The memory allocated in the heap is not partitioned based on threads, so, there is no concept of getting the memory usage of a thread (Stack is different but is pre-initialized to a fixed size and thus does not count for what you want to do). You need to implement a profiler (hooking to object instantiation for example) – Oguz Ozgul Apr 06 '20 at 10:54

0 Answers0