Sion Arrowsmith siona at
Wed Jan 30 14:03:08 CET 2008

Benjamin  <musiccomposition at> wrote:
>> [ help(sys.getrefcount) says: ]
>> [ ... ]  The count returned is generally
>> one higher than you might expect, because it includes the (temporary)
>> reference as an argument to getrefcount().
>Are there any cases when it wouldn't?

When the temporary reference which is the argument to getrefcount is
the *only* reference, eg:

>>> sys.getrefcount (set())

The return value for a weakly referenced object may also be not what
you "expect":

>>> s = set()
>>> sys.getrefcount(s)
>>> r = weakref.ref(s)
>>> r() is s
>>> sys.getrefcount(r())

\S -- siona at --
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list