Ordered dicts pretend to have the memory consumption as dicts: >>> import sys, collections >>> sys.getsizeof({}) 280 >>> sys.getsizeof(collections.OrderedDict()) 280
> How do you want to "handle this in general"? Possibly by adding up __sizeof__'s of base and __dict__ in a generated function? With a special handling of slots ... May prove to be too complicated to be worth the effort.
> > How do you want to "handle this in general"? > > Possibly by adding up __sizeof__'s of base and __dict__ in a generated > function? With a special handling of slots ... I agree that in the general case this would be better, but for OrderedDict it would still fail to give the right value (OrderedDict also needs to take into account its internal node objects).
I have a hard time caring about this. The main value of sys.getsizeof() is to enable developers to determine the internal sizes of basic objects on a given build. IIRC, there was no intention for this to become a requirement for pure python classes.