[Numpy-discussion] PyArray_Resize reference counting

Travis E. Oliphant oliphant@enthought....
Tue Sep 30 17:54:21 CDT 2008

Ravi wrote:
> On Tuesday 30 September 2008 16:26:08 Travis E. Oliphant wrote:
>> You need to do something like:
>> temp = PyArray_Resize(array,...)
>> Py_DECREF(array)
>> array = temp
> In this case, since a new array may be returned, is there no way to 
> synchronize with other objects holding a reference to the original array? 
Hold on!!

I just went to the code and noticed that PyArray_Resize returns None.  
So, you certainly don't want to point array to it.  The array does not 
get any reference count changes.

There are three concepts here:

1) The array object
2) The memory for the array
3) The reference count on the array object

PyArray_Resize doesn't change 1) or 3), it changes 2)


PyObject *dummy;
dummy = PyArray_Resize(array, ...)
if (dummy == NULL) goto fail;

is what you need to do.


More information about the Numpy-discussion mailing list