简体   繁体   English

如何在给定的 .NET 应用程序中查看 memory 分配?

[英]How do I see memory allocation in a given .NET application?

I need to check how much memory is allocated in the heap.我需要检查堆中分配了多少 memory。 Is there a way to get this value programmatically with C#?有没有办法使用 C# 以编程方式获取此值?

I know about the System.Runtime.InteropServices.Marshal.SizeOf(...) but that only tells me the size of an object.我知道System.Runtime.InteropServices.Marshal.SizeOf(...)但这只告诉我 object 的大小。

Using a PerformanceCounter you can query the "# Bytes in all Heaps", from your own process, and even other processes.使用PerformanceCounter ,您可以从您自己的进程甚至其他进程中查询“# Bytes in all Heaps”。

Use the Category ".Net CLR Memory" to see a lot of counters available.使用“.Net CLR 内存”类别查看大量可用的计数器。

You have to see what the difference in system load is between the PerformanceCounter and the GC.GetTotalMemory that is proposed by Jon Skeet.您必须查看由 Jon Skeet 提出的 PerformanceCounter 和 GC.GetTotalMemory 之间的系统负载差异。

Does GC.GetTotalMemory do everything you need? GC.GetTotalMemory能满足您的所有需求吗?

(Note that SizeOf only tells you the marshalled size, too - not necessarily the size in memory.) (请注意, SizeOf也只告诉您编组后的大小 - 不一定是 memory 中的大小。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM