找出多少内存被使用在C#中的对象? [英] Find out how much memory is being used by an object in C#?

查看:177
本文介绍了找出多少内存被使用在C#中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道的一种方式来找出多少内存对象的实例走?

Does anyone know of a way to find out how much memory an instance of an object is taking?

例如,如果我有以下对象的实例

For example, if I have an instance of the following object:

识别TestClass TC =新识别TestClass();

TestClass tc = new TestClass();

有没有办法找出多少内存例如TC走?

Is there a way to find out how much memory the instance "tc" is taking?

之所以要求是,尽管C#有内置的内存管理,我经常碰到的问题与不清除的对象的实例(例如,一个跟踪的东西列表)。

The reason for asking, is that although C# has built in memory management, I often run into issues with not clearing an instance of an object (e.g. a List that keeps track of something).

有几个相当不错的内存分析器(如蚂蚁探查),但在多线程环境中是相当困难的找出其中,属于什么即使有这些工具。

There are couple of reasonably good memory profilers (e.g. ANTS Profiler) but in a multi-threaded environment is pretty hard to figure out what belongs where, even with those tools.

推荐答案

如果你是不是要做到这一点在代码本身,我根据你的蚂蚁参考假设,尝试服用看看CLRProfiler(目前V2.0)。它是免费的,如果你不介意的相当简单的用户界面,它可以提供有价值的信息。它会给你各种统计资料的深入概述。我用它一会儿回来作为查找内存韭菜一个刀具

If you are not trying to do it in code itself, which I'm assuming based on your ANTS reference, try taking a look at CLRProfiler (currently v2.0). It's free and if you don't mind the rather simplistic UI, it can provide valuable information. It will give you a in-depth overview of all kinds of stats. I used it a while back as one tool for finding a memory leek.

在这里下载:的 http://www.microsoft.com/downloads/details.aspx?FamilyId=A362781C-3870-43BE-8926-862B40AA0CD0&displaylang = EN

如果你想做到这一点在代码中,CLR也分析你可以使​​用的API。如果您发现CLRProfiler的信息,因为它使用这些API,你应该能够做到这一点的代码了。更多资讯:
http://msdn.microsoft.com/de -de /杂志/ cc300553(EN-US)的.aspx

If you do want to do it in code, the CLR has profiling APIs you could use. If you find the information in CLRProfiler, since it uses those APIs, you should be able to do it in code too. More info here: http://msdn.microsoft.com/de-de/magazine/cc300553(en-us).aspx

(它并不像使用WinDbg成为一个神秘的,而是准备做强大深入CLR)

(It's not as cryptic as using WinDbg, but be prepared to do mighty deep into the CLR.)

这篇关于找出多少内存被使用在C#中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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