Process Memory Size - Different Counters

前端 未结 7 2012
闹比i
闹比i 2020-12-30 04:46

I\'m trying to find out how much memory my own .Net server process is using (for monitoring and logging purposes).

I\'m using:

Process.GetCurrentProc         


        
7条回答
  •  梦毁少年i
    2020-12-30 04:53

    Is this a fair description? I'd like to share this with my team so please let me know if it is incorrect (or incomplete):

    There are several ways in C# to ask how much memory my process is using.

    • Allocated memory can be managed (by the CLR) or unmanaged.
    • Allocated memory can be virtual (stored on disk) or loaded (into RAM pages)
    • Allocated memory can be private (used only by the process) or shared (e.g. belonging to a DLL that other processes are referencing).

    Given the above, here are some ways to measure memory usage in C#:

    1) Process.VirtualMemorySize64(): returns all the memory used by a process - managed or unmanaged, virtual or loaded, private or shared.

    2) Process.PrivateMemorySize64(): returns all the private memory used by a process - managed or unmanaged, virtual or loaded.

    3) Process.WorkingSet64(): returns all the private, loaded memory used by a process - managed or unmanaged

    4) GC.GetTotalMemory(): returns the amount of managed memory being watched by the garbage collector.

提交回复
热议问题