How can I determine how much memory my program is currently occupying

前端 未结 4 1628
忘了有多久
忘了有多久 2021-01-01 01:13

Related to my previous question:
Preventing Memory issues when handling large amounts of text

Is

相关标签:
4条回答
  • 2021-01-01 01:25

    You really need to use a code Profiler. These will tell you exactly what's happening, where the memory is being used up, etc.

    FYI: It's rarely where you think it is.

    0 讨论(0)
  • 2021-01-01 01:44
    long bytes = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;
    0 讨论(0)
  • 2021-01-01 01:51

    You can try GC.GetTotalMemory:

    Retrieves the number of bytes currently thought to be allocated. A parameter indicates whether this method can wait a short interval before returning, to allow the system to collect garbage and finalize objects.

    The important thing to note is this part: "Retrieves the number of bytes currently thought to be allocated". This means that this method may not be 100% accurate - as long as you know this going in, you should be able to get a rough idea of your virtual memory utilization at a given point in your application execution.

    Edit: Let me now offer a different solution that will probably be more productive: use perfmon and the CLR performance counters.

    0 讨论(0)
  • 2021-01-01 01:51

    long bytes = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 for more See Here

    0 讨论(0)
提交回复
热议问题