Are there ways at determining the total size of a complex object in .NET? This object is composed of other objects and might hold references to other complex objects. Some of the objects encapsulated by this object might be POD, others may not.
Share
What you have is not a “complex object”, it’s an object graph. To determine its total size, you need to walk that graph – starting with some root object, and using Reflection to enumerate fields of reference types and retrieving their values (and checking for loops, of course).
To get the size of a particular object in the graph, see this answer to a related question, but note that this is an evil hack, completely unsupported, may break (and may already be broken), and may result in a wholesale kitten genocide in heavenly spheres. That said, there is no “non-hacky” way to get a precise value, because it is an implementation detail by definition – you shouldn’t have any use for it. And for the purpose of finding out the memory usage of an app during debugging/profiling, the hack is good enough.