[SciPy-user] How to delete unused array in SciPy

Gael Varoquaux gael.varoquaux@normalesup....
Sun Jan 13 08:05:38 CST 2008


On Sun, Jan 13, 2008 at 03:00:47PM +0100, Lorenzo Isella wrote:
> While using SciPy to postprocess some large datasets, I often run out
> of memory. I think that this could be improved if I was able to get rid
> of some large arrays I need only at some point in my calculations. How
> do I remove an array in Python? Apart from re-defining it as something
> "smaller", is there a way to free the memory which had been allocated
> for that array?

The manual way is to use the "del" operator: if a is the array you want
to delete, "del a" will do want you want.

The clean way of doing this is to use functions to limit the scope of the
array a: if you define "a" in a function, when you exit the function, if
no references to a out of the function have been passed, a is
automatically garbage collected. One can't say it too many times: make
your code modular, limit the size of your functions. This is good design
to make it reusable/easy to modify, it it will improve your memory foot
print in the cases you are interested in.

HTH,

Gaël


More information about the SciPy-user mailing list