By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

refcount differences in 2.5

P: n/a
Hi

With Python 2.5, there is a change on the reference count of objects
compared with previous versions (as reported by sys.getrefcount).

All Python versions from 2.1 thru 2.4 gave these same results:

Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>import sys
sys.getrefcount(11111111)
2
>>sys.getrefcount(11111111+1)
1
>>x=22222222
sys.getrefcount(x)
2
>>sys.getrefcount(x+1)
1
>>sys.getrefcount("A unique *str-ing*")
2
>>sys.getrefcount("A unique *str-ing*".upper())
1
>>sys.getrefcount(3+2j)
1
>>class W: pass
....
>>x=W()
sys.getrefcount(x)
2
>>sys.getrefcount(W())
1
>>>
But Python 2.5 (2.5.1 not tested yet) gives different results:
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
on win
32
>>import sys
sys.getrefcount(11111111)
3
>>sys.getrefcount(11111111+1)
2
>>x=22222222
sys.getrefcount(x)
2
>>sys.getrefcount(x+1)
1
>>sys.getrefcount("A unique *str-ing*")
3
>>sys.getrefcount("A unique *str-ing*".upper())
1
>>sys.getrefcount(3+2j)
2
>>class W: pass
....
>>x=W()
sys.getrefcount(x)
2
>>sys.getrefcount(W())
1
>>>
In particular, I wonder why getrefcount(12341234) returns 3 instead of 2-
who is holding the extra reference?

My main two concerns are:
- is there a reference leak somewhere?
- it's a bit harder to debug my own references since I don't know
beforehand the value I should expect from sys.getrefcount()

--
Gabriel Genellina

May 16 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.