如何查看内存分配在一​​个给定的.NET应用程序? [英] How do I see memory allocation in a given .NET application?

查看:98
本文介绍了如何查看内存分配在一​​个给定的.NET应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查多少内存在堆中分配的。有没有办法让这个值编程使用C#?

I need to check how much memory is allocated in the heap. Is there a way to get this value programmatically with C#?

我知道关于 System.Runtime.InteropServices.Marshal.SizeOf(...),但只告诉我一个物体的大小。

I know about the System.Runtime.InteropServices.Marshal.SizeOf(...) but that only tells me the size of an object.

推荐答案

使用<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx">PerformanceCounter您可以查询字节数在所有堆,从自己的过程,甚至是其他进程。

Using a PerformanceCounter you can query the "# Bytes in all Heaps", from your own process, and even other processes.

使用的范畴.NET CLR内存看到很多可用的计数器。

Use the Category ".Net CLR Memory" to see a lot of counters available.

您必须看到在系统负载的不同之处是提出了乔恩飞碟双向的的PerformanceCounter和GC.GetTotalMemory之间有什么。

You have to see what the difference in system load is between the PerformanceCounter and the GC.GetTotalMemory that is proposed by Jon Skeet.

这篇关于如何查看内存分配在一​​个给定的.NET应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆