I tried to figure out how python stores the object reference count:
getrefcount(...)
getrefcount(object) -> integer
Return the reference count of object. The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().
>>>
>>> s = 'string'
>>> sys.getrefcount(s)
28
>>> d = {'key' : s}
>>> sys.getrefcount(s)
29
>>> l = [s]
>>> sys.getrefcount(s)
30
>>> del l
>>> sys.getrefcount(s)
29
>>> del d
>>> sys.getrefcount(s)
28
>>>
In my above snippet, as soon as I create a string object s, I got a reference count of 28, and then when I assigned inside the dictionary its count counter to one. And I don't know why it starts at 28.
So here I am trying to figure out where these values are stored or how python works.
thanks
user3058156
source
share