[Numpy-discussion] PyArray_Resize reference counting

Ravi lists_ravi@lavabit....
Tue Sep 30 14:48:09 CDT 2008


Hi,
  Consider the following code:

   PyArrayObject *array = get_me_an_array_along_with_a_reference(); /* 1 */
   PyArray_Dims *dims = get_me_some_dims(); /* 2 */
   array = (PyArrayObject *)PyArray_Resize( array, dims, 1 ); /* 3 */

Is the code above valid? In particular, is the assigment on line 3 valid? 
Travis' book says that a reference to the new array is returned. Does that 
mean that I need to store a pointer to the original array somewhere else and 
decrement its reference count after the resize call?

Alternatively, if I don't need to store the pointer because the returned 
pointer is the same as the one passed into the resize function, do I need to 
decrement the reference count since I already have a reference to the array? 
In other words, if the reference count is, say, 16 before line 1 and 17 after 
line 1, will it be 18 after line 3? In that case, I need to decrement the 
reference once to get it back to 17 because I should not need a reference as I 
already have one.

Regards,
Ravi




More information about the Numpy-discussion mailing list