Jad*_*ias 53 .net c# memory performance memory-management
如何在.NET中以编程方式测量当前进程的总内存消耗?
Hot*_*ter 53
请参阅此SO问题
再试试这个
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
Run Code Online (Sandbox Code Playgroud)
Ada*_*lph 32
如果您只想测量由某些不同操作引起的虚拟内存使用量的增加,您可以使用以下模式: -
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
var before = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
// performs operations here
var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
Run Code Online (Sandbox Code Playgroud)
当然,这是假设您的应用程序在上述操作运行时不在其他线程上执行操作.
您可以VirtualMemorySize64
使用您感兴趣的任何其他指标进行替换.请查看System.Diagnostics.Process
类型以查看可用的指标.
归档时间: |
|
查看次数: |
52328 次 |
最近记录: |