From: Reggie D. <re...@me...> - 2002-02-23 01:25:19
|
I believe PyArray_FromDims() returns a new reference to the object (arr)= =20 and that the Py_BuildValue creates another reference so that you've got = two references to that array and python is only going to DECREF one when= =20 it's done. I would suggest either 1) using the 'N' format character to = Py_BuildValue so that another reference isn't created or 2) explicitly=20 calling Py_DECREF(arr) just before you return. Reggie >>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<< On 2/22/02, 4:19:15 PM, Mathew Yeates <ma...@fu...> wrote = regarding [Numpy-discussion] memory not being freed: > Hi > I'm having problems with garbage collection > I wrote an extension which creates an array > and returns it > foo() { > arr =3D (PyArrayObject *) PyArray_FromDims( ..... > ret =3D Py_BuildValue("O", arr); > return ret; > } > but now if I do > while 1: > a=3Dfoo() > memory is never free'd. I've even tried explicitly calling gc.collect = and > adding del(a) after a=3Dfoo. > Is the problem that Py_BuildValue increases the reference count? > Mathew > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion |