[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    Re: [C++-sig] create boost array from a Numpy PyArray without
From:       <AFoglia () princeton ! com>
Date:       2009-01-23 17:03:38
Message-ID: 4979F86A.3000204 () princeton ! com
[Download RAW message or body]

Sebastian Walter wrote:

>>> And is there a way to get the refcount of an object within Python? I'd
>>> like to test if the refcount is correct.
>> sys.getrefcount(obj)
> 
> Good to know. When I run
> - ------------------- test.py ----------------
> from _test import *
> import sys
> 
> def test_my_array():
> 	a = A()
> 	print 'a.my_array=',a.my_array
> 	print 'sys.getrefcount(a)=',sys.getrefcount(a)
> 	print 'sys.getrefcount(a.my_array)=',sys.getrefcount(a.my_array)
> 
> 
> if __name__ == "__main__":
> 	test_my_array()
> 
> - ------------ end test.py -------------
> I get the output
> 
> - ----------- output -------------
> 
> walter@wronski$ python test.py
> a.my_array= [ 1.  2.  3.]
> sys.getrefcount(a)= 2
> sys.getrefcount(a.my_array)= 2
> 
> - ----------- end output --------
> 
> Ermm, is that good?
> I expected that the refcount would be 1 and not 2.

When you call getrefcount, the argument becomes another reference, so 
there are two references.

http://docs.python.org/library/sys.html#sys.getrefcount

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


-- 
Anthony Foglia
Princeton Consultants

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic