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

前端 未结 4 1649
忘了有多久
忘了有多久 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: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.

提交回复
热议问题