【发布时间】:2014-09-18 21:14:33
【问题描述】:
这段代码在每次迭代中返回相同的值:
var process = Process.GetCurrentProcess();
for (int i = 0; i < 10; i++)
{
Console.WriteLine(process.PrivateMemorySize64 + Environment.NewLine);
}
// Output:
// 19853313
// 19853313
// 19853313
// 19853313
// ...
此代码返回不同的值:
for (int i = 0; i < 10; i++)
{
var process = Process.GetCurrentProcess();
Console.WriteLine(process.PrivateMemorySize64 + Environment.NewLine);
}
// Output:
// 19865600
// 20336640
// 20791296
// 21245952
// ...
Process.GetCurrentProcess() 是否拍摄内存值的快照?
MSDN 的 GetCurrentProcess 页面这样说,但我不确定这意味着什么:
Gets a new Process component and associates it with the currently active process
【问题讨论】: