There is no completely accurate way to determine instantiated object size, but this code shown in this example should get you pretty close:
private static long GetObjectSize(object obj)
{
long size = 0;
using (Stream s = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(s, obj);
size = s.Length;
}
return size;
}
I created a simple class with two string properties, and then another class that derives from the first one without any additional properties/code/fields.
The non-derived version (with the code above) showed 202 bytes.
The derived version showed 225 bytes.
There is some additional memory consumption (and that's to be expected), but I leave it up to you to determine if the increased memory consumption is linear or geometric with more complex base classes.
In the end, it really is irrelevant. You shouldn't code for (false/imagined?) memory optimization at the expense of maintainability.
If you're interested in memory allocation in .Net, just google it and read for as long as you can maintain interest in the subject.
I forgot to mention that the code I provided will only work if the classes in question have the
[Serializable]
attribute applied.
EDIT ==================================
After some cursory testing, it appears as if the length of the object names (and the names of their properties and methods) is a determining factor in how much additional memory is allocated to a derived class. Also, despite that, the amount of additional memory consumed by an inheriting class (given my very simple classes) appears to be a reasonably static percentage (around 11%).