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 が 1 ずつ増加します。なんで28から始まるのかわからない。
だから、ここで私はこの値がどこに保存されているか、またはpythonがどのようにそれを取得するかを理解しようとしています.
ありがとう