Skip to content

_debugmallocstats() undercounts bytes in type-specific free lists #148189

@tim-one

Description

@tim-one

Bug report

Bug description:

Toward the tail end of sys._debugmallocstats() output there's an account of bytes sitting in various type-specific free lists, like so:|

           62 free PyDictObjects * 48 bytes each =                2,976
       77 free PyDictKeysObjects * 32 bytes each =                2,464
           6 free PyFloatObjects * 24 bytes each =                  144
           60 free PyListObjects * 40 bytes each =                2,400
 231 free 1-sized PyTupleObjects * 40 bytes each =                9,240
...

However, for the container types that participate in cyclic gc (dict, list, tuple), the "bytes each" figurers are too small. Like:

Python 3.14.1 (tags/v3.14.1:57e0d17, Dec  2 2025, 14:05:07) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getsizeof([])
56

56 > 40, by 16. Same 16 missing for dicts and tuples. I suspect (but don't know) that they're missing the two pointers (before the PYObject's type pointer) used by cyclic gc to link together the members of a generation.

Labeling as "easy", because it has to 😉 be shallow. A good exercise for somene to sharpen their archeological skills.

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions