[SciPy-dev] refcount strangeness when testing weave

eric jones eric at enthought.com
Sun Sep 22 01:57:14 CDT 2002

I've made some modifications to the SCXX library to beautify code
written in C++ and also to improve speed in some cases.  I started
adding unit tests that exercised some of this stuff and ran into an
issue testing refcounts right off the bat.  

Testing that refcounts are handled correctly for a list passed into a
weave function (that does absolutely nothing) gives me the expected
results from the command line in the global namespace.

>>> import weave
>>> import sys
>>> a = []
>>> print sys.getrefcount(a)
>>> weave.inline('',['a'])
>>> print sys.getrefcount(a)

However, when doing the same in a function, I get different behavior:

>>> def bub():
...   a=[]
...   print sys.getrefcount(a)
...   weave.inline('',['a'])
...   print sys.getrefcount(a)
...   weave.inline('',['a'])
...   print sys.getrefcount(a)
>>> bub()

After the first call to weave, it looks like a reference count that
shouldn't be added to 'a' gets added.  However, running the weave call
again doesn't leak a ref count.  Based, on this and the original command
line result, I'm pretty sure refcounts are handled correctly.  

Can someone explain what is happening here that is causing the refcount
to rise to 3 on the first call in bub() so that I can right accurate
tests for weave and ref counts?


More information about the Scipy-dev mailing list