我试图弄清楚python如何存储对象的引用计数:
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
>>>
在我上面的代码片段中,一旦我创建了一个字符串对象,s
我就得到了 ref-count 28,然后当我在字典中分配它的 ref-count 时,它的 ref-count 增加了 1。我不知道为什么它以 28 开头。
所以,在这里我试图弄清楚这个值存储在哪里或 python 如何获取它。
谢谢