On this page
sys.getrefcount
Prev: sys.getrecursionlimit | Up: sys | Next: sys.getsizeof
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.getrefcount
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import getrefcount
Signature & Overview
sys.getrefcount(object, /)
Return the reference count of object.
Usage
import sys
obj = object()
# At least 2: one for `obj`, plus one temporary reference for the getrefcount() argument
assert sys.getrefcount(obj) >= 2
Gotchas
- Always includes +1 for the function argument itself: Small ints and interned strings have huge or immortal reference counts in CPython 3.12+.
REPL Inspect
from sys import getrefcount
help(getrefcount)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/getrecursionlimit Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/getsizeof Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys/activate_stack_trampoline Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/addaudithook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/audit Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/breakpointhook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/call_tracing shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/deactivate_stack_trampoline shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/displayhook shared tags: #stdlib, #sys