I want to know how the memory allocated in python.For that,I used to playing on python.But I got stuck on below issue.
For the below code, If I use 10 instead of 1000 I got expected reference count value within the function
import sys
def show_ref_count(a):
print("ref count of 1000 within function : ",sys.getrefcount(1000))
print("adrs of a : ",id(a))
# main function
a = 1000
b = 1000
c = 1000
print("ref count of 1000 : ",sys.getrefcount(1000))
print("adrs of a : ",id(a))
show_ref_count(a)
And the output for the code is
ref count of 1000 : 6
adrs of a : 140309334530448
ref count of 1000 within function : 3
adrs of a : 140309334530448
Integer 1000 stored in Memory loc : 140309334530448 and same address used by both main and show_ref_count. But in show_ref_count function, reference count for 1000 is showing as 3 not 7.Why?