Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: refcount

Reply
Thread Tools

Re: refcount

 
 
Christian Heimes
Guest
Posts: n/a
 
      01-29-2008
Simon Pickles wrote:
> Hi,
>
> Is is possible to access the refcount for an object?
>
> Ideally, I am looking to see if I have a refcount of 1 before calling del


Help on built-in function getrefcount in module sys:

getrefcount(...)
getrefcount(object) -> integer

Return the reference count of object. The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().

Christian

 
Reply With Quote
 
 
 
 
Benjamin
Guest
Posts: n/a
 
      01-29-2008
On Jan 29, 5:46 am, Christian Heimes <li...@cheimes.de> wrote:
> Simon Pickles wrote:
> > Hi,

>
> > Is is possible to access the refcount for an object?

>
> > Ideally, I am looking to see if I have a refcount of 1 before calling del

>
> Help on built-in function getrefcount in module sys:
>
> getrefcount(...)
> getrefcount(object) -> integer
>
> Return the reference count of object. 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?
>
> Christian


 
Reply With Quote
 
 
 
 
Mel
Guest
Posts: n/a
 
      01-29-2008
Benjamin wrote:
> On Jan 29, 5:46 am, Christian Heimes <li...@cheimes.de> wrote:
>> Simon Pickles wrote:
>>> Hi,
>>> Is is possible to access the refcount for an object?
>>> Ideally, I am looking to see if I have a refcount of 1 before calling del

>> Help on built-in function getrefcount in module sys:
>>
>> getrefcount(...)
>> getrefcount(object) -> integer
>>
>> Return the reference count of object. 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?


Well, as long as the object is named "object" in sys.getrefcount's
namespace, there's at least that one reference to it...

Mel.
 
Reply With Quote
 
Sion Arrowsmith
Guest
Posts: n/a
 
      01-30-2008
Benjamin <> 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())

1

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

>>> s = set()
>>> sys.getrefcount(s)

2
>>> r = weakref.ref(s)
>>> r() is s

True
>>> sys.getrefcount(r())

2

--
\S -- -- http://www.chaos.org.uk/~sion/
"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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PyDict_*() refcount assumptions sndive@gmail.com Python 1 11-01-2007 05:14 AM
refcount differences in 2.5 Gabriel Genellina Python 0 05-16-2007 11:15 PM
beginner's refcount questions Jens Theisen Python 3 10-30-2006 07:07 AM
Debugging leaking refcount Jean-Franēois Doyon Python 0 05-14-2004 06:08 PM
[Q] Extension: Refcount for exception types Ames Andreas (MPA/DF) Python 1 04-16-2004 07:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57