Python memory deallocate

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu May 11 09:14:39 EDT 2006


 <mariano.difelice at gmail.com> wrote:
>If I write:
>
>a = range(500*1024)
>
>I see that python process allocate approximately 80Mb of memory.
>What can i do for DEALLOCATE this memory, or good part of this?
> [ ... ]
>I've tried with Destroy, del command, but the memory don't show down.

It won't (much). When an object gets garbage collected Python
will keep hold of the memory and reuse it. Note how much memory
your process is using after assigning a above, then:

>>> del a

Of course, you've seen this doesn't release back to the OS all
the memory being that was being used. But now do:

>>> a = range(500*1024)

and you'll see that you're using no more memory than you were
after the first assignment. If your memory usage keeps on growing
then either (a) your program needs that much memory for the data,
and you'll just have to stick more in your box or deal with
swapping if this is causing you a problem or (b) you've got some
stray references left over to objects you think you've deleted.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list