[Matrix-SIG] Numpy array.tolist() memory leak ?

Jonah Lee ffjhl@uaf.edu
Wed, 7 Oct 1998 14:28:22 -0800 (AKDT)


On Sun, 27 Sep 1998, David Ascher wrote:
Hi,

Thanks for the suggestion. I've played with this and other possibilities
for a while but could not get the problem solved. I think one of the
problems may be that the procedure is called recursively which makes the
release of memory less intuitive. I would appreciate it if anyone could
see a solution to this situation. I've used a workaround in my application
code to avoid using this particular method but would still like to see a
solution one day. Thanks.

> 
> 
> On Sun, 27 Sep 1998, Jonah Lee wrote:
> > 
> > There seems to be a memory leak with the following example:
> > 
> > from Numeric import *
> > a=array([[1,2,3],[4,5,6],[7,8,9]], Float)
> > for i in range(100000):
> >     for j in range(100000):
> >         c=a.tolist()
> > 
> > If a=array([1,2,3,4]), then there is no leak.
> > 
> > Any advice on this would be appreciated. Thanks.
> 
> I could be wrong (reference counting was never my forte), but I believe
> that arrayobject.c's PyArray_ToList() should be modified to read:
> 
>         ...
> 
> 	for (i=0; i<sz; i++) {
> !           PyArrayObject *elt;
> !           elt = array_item((PyArrayObject *)self, i);
> !           PyList_SetItem(lp, i, PyArray_ToList(elt));
> !           Py_DECREF(elt);
> 	}
> 
>         ...
> 
> otherwise the subarrays ([1,2,3] etc. in the example above) never get
> DECREF'ed out.
> 
> --david ascher
> 
> 
> _______________________________________________
> Matrix-SIG maillist  -  Matrix-SIG@python.org
> http://www.python.org/mailman/listinfo/matrix-sig
> 

Regards,
Jonah