[SciPy-user] How to free memory allocated to array in weave.inline?

Gael Varoquaux gael.varoquaux@normalesup....
Sat Aug 25 06:45:20 CDT 2007

On Sat, Aug 25, 2007 at 11:37:46PM +1200, Angus McMorland wrote:
> The code generates a 3-D array, and loops through the array assigning
> values based on the co-ordinate position. In the final program this
> array generation has to be done many (ideally 1000s) of times, but
> when I try this my memory consumption increases.

My rule of thumb when I create arrays in C code, is not to create arrays
in C code. Your problem is most probably that your memory does not get
freed, as it it not registered in Python's garbage collector. You could
learn how to do this (I don't know how). The other option is to use
numpy.empty to create an empty array, and pass it to your code that will
populate it. That way you don't have to deal with all this. It alos makes
your cod emore readable: no PyArrayObject* and co. in it.

My 2 cents,


More information about the SciPy-user mailing list