### Documentation ## Problem The docstrings for `object.__sizeof__` and `sys.getsizeof` are practically identical (`"Size of object in memory, in bytes."` vs `"Return the size of object in bytes."`), despite returning different values for the same object. Neither docstring explains: - Why the two values differ - When they differ - What each one actually measures This has caused confusions: - https://stackoverflow.com/questions/55427689/difference-between-sizeof-and-sys-getsizeof - https://stackoverflow.com/questions/42051378/sizeof-not-getting-called-by-sys-getsizeof ### Example ``` >>> x = [1, 2, 3] >>> print(x.__sizeof__()) 72 >>> print(sys.getsizeof(x)) 88 ``` ## Get docstrings ``` help(object.__sizeof__) import sys help(sys.getsizeof) ``` --- ``` Help on method_descriptor: __sizeof__(self, /) unbound builtins.object method Size of object in memory, in bytes. ``` > Output of **help(object.__sizeof__)** ``` Help on built-in function getsizeof in module sys: getsizeof(...) getsizeof(object [, default]) -> int Return the size of object in bytes. ``` > Output of **help(sys.getsizeof)** ## Proposed fix **object.__sizeof__:** ``` __sizeof__(self, /) unbound builtins.object method Size of object in memory, in bytes, excluding internal interpreter overhead. Use sys.getsizeof() to get the total size. ``` **sys.getsizeof:** ``` getsizeof(...) getsizeof(object [, default]) -> int Return the total size of object in bytes, including internal interpreter overhead (such as the garbage collector header). Calls the object's __sizeof__ method and adds the overhead. ``` ## Related source code - `sys.getsizeof` implementation [code](https://github.com/python/cpython/blob/cb76ab3819f778e55a3f49ddb1f681ee20978eda/Python/sysmodule.c#L1928) - `__sizeof__` implementation [code](https://github.com/python/cpython/blob/cb76ab3819f778e55a3f49ddb1f681ee20978eda/Objects/clinic/typeobject.c.h#L243) --- I'd like to submit a pull request for these docstring changes once we agree on the wording. Feel free to suggest any edits to the proposed text.