I have an inmemory cache (.NET 6), like this:
struct CacheItem
{
private byte[] content;
private long lastUsage;
/// other fields
}
var cache = new ConcurrentDictionary<string, CacheItem>();
I would like to find out, how much memory do I spend on it. I can get rough estimation, using GC Gen 2 heap size, but this heap contains not only my cache.
Also, I may try to calculate inmemory cache size from an application, adding a string size, a content size, a struct size, but it will give really rough estimation, because I don't know, how fields are aligned, and I don't know object headers, and so on.
So, I can take a full memory dump. I know, that it is possible to get an object size, using WinDbg, but in my case I want to get a Retained size (meaning, with sizes of all data inside it) of the whole Dictionary
. So, is it possible to do, using WinDbg
, or any other tool?