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:
How to get object size in memory?
C#: Memory usage of an object
Find out the size of a .net object
How much memory does a C#/.NET object use?
and the list goes on an on...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With