◐ Shell
clean mode source ↗

Message 66994 - Python tracker

It's actually not possible, in general, to compute the memory
consumption of an object using basicsize and itemsize. An example is the
dictionary, where there is no way to find out how many slots are
currently allocated.

Even for the things such as lists where the formula
basicsize+len*itemsize would be correct it may fail, e.g. a list reports
its itemsize as zero, even though each list item consumes four bytes (on
a 32-bit system).

I don't really see a problem with calling it sizeof, so I would then
propose sys.sizeof as the appropriate location.