diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst new file mode 100644 index 00000000000000..d90e30b3d3fba8 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-08-02-49-07.gh-issue-148189.0KpXID.rst @@ -0,0 +1 @@ +Repaired undercount of bytes in type-specific free lists reported by sys._debugmallocstats(). For types that participate in cyclic garbage collection, it was missing two pointers used by GC. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 67bc4319e0bae2..fc8f3a6209698b 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -443,7 +443,7 @@ _PyDict_DebugMallocStats(FILE *out) { _PyDebugAllocatorStats(out, "free PyDictObject", _Py_FREELIST_SIZE(dicts), - sizeof(PyDictObject)); + _PyType_PreHeaderSize(&PyDict_Type) + sizeof(PyDictObject)); _PyDebugAllocatorStats(out, "free PyDictKeysObject", _Py_FREELIST_SIZE(dictkeys), sizeof(PyDictKeysObject)); diff --git a/Objects/listobject.c b/Objects/listobject.c index 5c9fd55bab1b22..2e53a440584786 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -234,7 +234,7 @@ _PyList_DebugMallocStats(FILE *out) _PyDebugAllocatorStats(out, "free PyListObject", _Py_FREELIST_SIZE(lists), - sizeof(PyListObject)); + _PyType_PreHeaderSize(&PyList_Type) + sizeof(PyListObject)); } PyObject *