Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.getsizeof() does not include inline values #128762

Open
hashbrowncipher opened this issue Jan 12, 2025 · 0 comments
Open

sys.getsizeof() does not include inline values #128762

hashbrowncipher opened this issue Jan 12, 2025 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@hashbrowncipher
Copy link
Contributor

hashbrowncipher commented Jan 12, 2025

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

Linked PRs

@hashbrowncipher hashbrowncipher added the type-bug An unexpected behavior, bug, or error label Jan 12, 2025
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants