如何衡量一个单独的对象需要在.NET中的内存量 [英] How to measure the amount of memory an individual object takes in .NET

查看:152
本文介绍了如何衡量一个单独的对象需要在.NET中的内存量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果有一个简单的命令或指令在C#/。NET和/或Visual Studio,可以告诉我一个单独的对象了多少内存占用?我有一个鬼鬼祟祟的怀疑,大小()运算符是要骗我...我是合理的,这种信念?

I'm wondering if there is a simple command or instruction in C#/.NET and/or Visual Studio that can tell me how much memory an individual object is taking up? I have a sneaking suspicion that the sizeof() operator is going to lie to me ... am I justified in this belief?

有一个有点相关的问题这里,但没有明确的答案给出的如何测量单个对象

There is a somewhat related question here, but no definitive answer is given on how to measure an individual object

推荐答案

有没有明确的方式,因为它只是任何类型的对象并不简单。

There is no definitive way because it's not simple for just any type of object.

如果该对象包含对其他对象?如果这些对象有其它对象引用它们?哪一个对象实际拥有的内存空间?它是在创建它的一个或最后一个去触摸它?在任何一点它可能具有不同的所有者。或者你只是关心多少空间参考需要?

What if that object contains references to other objects? What if those other objects have other objects referencing them? Which object actually owns that memory space? Is it the one that created it or the last one to touch it? At any one point it could have different owners. Or do you just care about how much space the reference takes?

也有一吨的问题已经问过这个,以及...一个快速搜索变成了:

There is also a ton of questions that have asked this as well... a quick search turns up:

<一个href="http://stackoverflow.com/questions/605621/how-to-get-object-size-in-memory">http://stackoverflow.com/questions/605621/how-to-get-object-size-in-memory

<一个href="http://stackoverflow.com/questions/555929/c-memory-usage-of-an-object">http://stackoverflow.com/questions/555929/c-memory-usage-of-an-object

<一个href="http://stackoverflow.com/questions/324053/find-out-the-size-of-a-net-object">http://stackoverflow.com/questions/324053/find-out-the-size-of-a-net-object

<一个href="http://stackoverflow.com/questions/426396/how-much-memory-does-a-c-net-object-use">http://stackoverflow.com/questions/426396/how-much-memory-does-a-c-net-object-use

和不胜枚举的上...

and the list goes on an on...

这篇关于如何衡量一个单独的对象需要在.NET中的内存量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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