ob_refcnt INCREF and so on...
jkraska1 at san.rr.com
Sat May 27 20:44:32 CEST 2000
I'm currently working on a deque implementation, and I believe I now
understand python reference counts. However, one small little thing
puzzles me which I'd like resolved before I can say "I grok this."
In my efforts to grok references, I wrote a function to print the
ob_refcnt of python objects so I could test my understanding of
the reference system.
Here's where I'm a bit sketchy:
In the above code fragment, checkref(o) prints "2". The object "o"
has two references to it, and I'm not sure why. The closest thing
I have to a theory is that at the point of creating the argument,
"o" is assigned to a temporary tuple which grabs a reference count
to "o" (I based this theory on the knowledge that I have to parse
a tuple in the C extension code).
Can someone confirm or deny this, and if I'm mistaken, explain why
the refcnt of the object is 2 at the point where I print it??????
If correct, is there a predictable time when the temporary will
lose it's reference hold on the object?
More information about the Python-list