[Numpy-discussion] memmory management question

Daπid davidmenhur at gmail.com
Mon Oct 28 08:22:23 EDT 2013

On 28 October 2013 03:13, Georgios Exarchakis <gexarcha1 at gmail.com> wrote:

> If yes then how do you release memorry by slicing away parts of an array?

An array is a single Python object. In your example, there is always one
reference pointing to the array (either the whole array or only a view), so
the memory cannot be released.

In your case, a = a[:10000].copy() releases the memory by creating a new
object and pointing a to this new one, so the big array gets unreferenced
and thus, garbage collected. The price to pay is that, for some time, you
have living in memory both the original array and your new one: if they
were very big, you could run out of memory; and that you have to perform a
memcopy (again, slow if you have lots of data).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131028/33b7701f/attachment.html>

More information about the NumPy-Discussion mailing list