Open
Description
Bug report
Bug description:
Commit tested: 5e65a1a
I have a program that allocates numerous instances of this type:
@dataclass
class Node:
cdr: Self | None
BIG_DATA = None
for i in range(50):
BIG_DATA = Node(BIG_DATA)
print(sys.getsizeof(BIG_DATA))
After the 28th iteration, I find that it stabilizes at printing 48. But if I run the program in GDB and trace the actual allocations, I see that it is allocating 80 bytes per iteration:
# Set a GDB-recognized breakpoint
os.kill(os.getpid(), signal.SIGTRAP)
# In GDB:
# b _PyObject_Malloc
# commands
# silent
# print nbytes
# continue
# end
for i in range(50):
BIG_DATA = Node(BIG_DATA)
I believe that the missing bytes can be accounted for in the inline values. I observe the same behavior on Python 3.13.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux