Getting the reference count
Tim Peters
tim_one at email.msn.com
Sun Aug 27 06:19:01 EDT 2000
> Is it possible to get the reference count of a PyObject* object?
> I'm surre it must be, but I can't see it documented anywhere.
>
> Something similar to Perl's SvREFCNT() Macro would be great.
All Python objects share a common format "at the start", including space for
the refcount, and the few places refcounts are looked at raw simply
reference the ob_refcnt field directly. For example,
assert(v->ob_refcnt == 1);
Note that incrementing or decrementing refcounts should always be done via
the macros defined for those purposes in object.h; it's rare to do anything
else with the refcounts.
omnipresent-yet-rarely-seen-ly y'rs - tim
More information about the Python-list
mailing list