[Numpy-discussion] views and object lifetime

Travis E. Oliphant oliphant@enthought....
Wed Feb 18 09:40:50 CST 2009

Neal Becker wrote:
> How is it ensured, at the C api level, that when I have an array A, and a view
> of it B, that the data is not destroyed until both A and B are?
One array, A, owns the data and will deallocate it only when its 
reference-count goes to 0.    The view, B, has a reference to A (stored 
in the base attribute) and has OWNDATA set to false so that its 
deallocator simply decreases the reference count on the array, A, that 
actually owns the data. 

In the code look at

the `array_dealloc` function  in arrayobject.c and the base and OWNDATA 
flag-bit in the array-structure for details.


More information about the Numpy-discussion mailing list