Debugging reference counts in python/C

K

karmadharma

Hello everybody

I am trying to make sure that my (non trivial) C module is cleaning up
properly after itself, and consequently I've built python with
--py-debug which, besides allowing me to use certain functions, it also
prints the reference count at the end.

I am finding, however, that the reference count on exit seems to
increase by 1 every time I create one of my objects, poring over the
output of the debugging functions seems to imply that the only thing
that changes is the refcount of

[somenumber] '<dummy key>'

where somenumber seems proportional to the number of objects I create,
if I create n+1 objects, somenumber increases by 1. Looking at the docs
this seems related to empty dictionaries, but I'm really stumped at the
moment.

Out of curiosity I also did this stupid test thinking it would return
the same refcount, but evidently it doesn't:

Type "help", "copyright", "credits" or "license" for more information.
[17214 refs]
[6606 refs]

Type "help", "copyright", "credits" or "license" for more information.
a=1 [17214 refs]
b=2 [17217 refs]
(ctrl-D)
[17217 refs]
[6608 refs]

as you can see just assigning another variable causes the refcount to
remain higher when python exits.

Is this something I should be worried about at all? I am new to writing
python C extensions, and that's why I never really worried about all
this before; apologies if my question is obvious and/or trivial...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top