PeakVirtualMemorySize64, PeakWorkingSet64 and PeakPagedMemorySize64 for a process have different value if we executed several time?

我怕爱的太早我们不能终老 提交于 2019-12-12 03:38:54

问题


I run a code multiple time and i measure in the end of it the PeakPagedMemorySize64 , PeakWorkingSet64 and PeakVirtualMemorySize64 using the Process class .

But in each time i get different value for the same code

PeakPagedMemorySize64 112758784 PeakVirtualMemorySize64 332701696   PeakWorkingSet64 143835136
PeakPagedMemorySize64 113696768 PeakVirtualMemorySize64 332636160   PeakWorkingSet64 144642048
PeakPagedMemorySize64 113528832 PeakVirtualMemorySize64 332701696   PeakWorkingSet64 144547840

why I have this different values instead of getting the same value each time? And how can I optimize it to minimize this variation?


回答1:


"Working set" is the amount of virtual memory which fits into physical RAM. The amount of physical RAM available depends on other programs as well, so this value changes over time. If the "working set" value changes due to other programs, so will the peak value.

In fact, you should be happy if this value is high: this means that all your data is in RAM and RAM is fast. If this value is low, some data has been swapped to disk and disk is very slow.

The question is: why do you want to measure this value? If you're looking for a memory leak, measure private bytes instead.

Since you have tagged this .net, the amount of private bytes heavily depends on the implementation of the .NET garbage collector. It may request more or less memory depending on garbage collections which ran or did not run previously and how much physical RAM was available at the time .NET requested additional memory the last time.

To see those internals, I recommend using windbg and sos. You can then see the amount of free memory of the .NET garbage collector.



来源:https://stackoverflow.com/questions/31945443/peakvirtualmemorysize64-peakworkingset64-and-peakpagedmemorysize64-for-a-proces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!