[issue12414] getsizeof() on code objects is wrong
Serhiy Storchaka
report at bugs.python.org
Sun Mar 26 09:49:22 EDT 2017
Serhiy Storchaka added the comment:
I concur with Martin. sys.getsizeof() should only count the memory that is not exposed as separate Python objects. In case of a code object this is the memory of the PyCodeObject structure and the memory of dynamic array co_cellvars (issue15456). Other subobjects are exposed as code object attributes and by gc.get_referents(). For counting the summary size you should recursively call sys.getsizeof() for objects returned by gc.get_referents(). But be aware that some subobjects (for example interned strings) can be shared between different code objects, so the average memory consumption is less than the simple sum.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12414>
_______________________________________
More information about the Python-bugs-list
mailing list