Measure size of .NET objects

Go To


I am writing an application in .NET 4.0 C#. I am placing objects in the .net httpruntime cache and want to produce some stats on it. I would like to know the size of the object before it put in to cache and the size of it in cache. How can I measure this? Is it serialized when put in to cache and if so what type of serialization is used?

2012-04-03 22:41
by amateur


The HTTP Runtime Cache does not serialize data at all, it just places it in a hash table:

What is the default serialization used by the HttpRuntime.Cache

There are several methods to get or estimate the size of a .NET object in memory:

How to get object size in memory?

It's not possible to directly know the number of bytes consumed by a .NET object:

2012-04-03 22:46
by Eric J.