[Numpy-discussion] Accessing array members

Konrad Hinsen hinsen at cnrs-orleans.fr
Mon Dec 2 03:42:12 EST 2002

Joachim Saul <list at jsaul.de> writes:

> But what if I create a reference to foo.bar, and later delete foo,
> i.e.
> >>> b = foo.bar
> >>> del foo
> Now the data pointer in b refers to freed data! In the mentioned

And that is why the condition for using PyArray_FromDimsAndData is
that the data space passed is not freed before the end of the process.

> survive the actual 'foo' object. However, I want to program it the
> 'clean' way; any hints on how to do it properly would therefore be
> highly welcome.

I see only one clean solution: implement your own array-like object
that represents foo.bar. This object would keep a reference to foo
and release it when it is itself destroyed.

Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-
Rue Charles Sadron                       | Fax:  +33-
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais

More information about the NumPy-Discussion mailing list