[Numpy-discussion] views and object lifetime

Travis E. Oliphant oliphant at enthought.com
Wed Feb 18 10:40:50 EST 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.


-Travis




More information about the NumPy-Discussion mailing list