2. reference_count

Run Settings
LanguagePython
Language Version
Run Command
import sys a = [1,2,3] print(hex(id(a))) # a is passing into a function, so a counter become 2, can't use normal python to check print(sys.getrefcount(a)) # write a function with c code to check import ctypes def ref_count(address: int): return ctypes.c_long.from_address(address).value print(ref_count(id(a))) b = a print(hex(id(b))) print(ref_count(id(a))) # interesting b = None print(id(b)) # keep the id of a and see what happen after a is pointing to other value a_id = id(a) a = None print(ref_count(a_id)) print(ref_count(a_id))
Editor Settings
Theme
Key bindings
Full width
Lines