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

查看:23
本文介绍了如何查看给定 .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.

推荐答案

使用 PerformanceCounter 你可以从你自己的进程,甚至其他进程中查询# Bytes in all Heaps".

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 和 Jon Skeet 提出的 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天全站免登陆