[Numpy-discussion] PyArray_Resize reference counting
Tue Sep 30 14:48:09 CDT 2008
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.
More information about the Numpy-discussion