How is memory managed in python?

Chris Rebert clp2 at rebertia.com
Tue Jul 20 02:43:38 EDT 2010


On Mon, Jul 19, 2010 at 6:30 PM, Vishal Rana <ranavishal at gmail.com> wrote:
> Hi,
> In my web application (Django) I call a function for some request which
> loads like 500 MB data from the database uses it to do some calculation and
> stores the output in disk. I just wonder even after this request is served
> the apache / python process is still shows using that 500 MB, why is it so?
> Can't I release that memory?

http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm

There are multiple layers of memory allocation involved. To avoid
thrashing+fragmentation and to improve efficiency, free memory is not
always immediately returned to the operating system. Example: If your
problem involved calling your 500MB function twice, free-ing after the
first call and then immediately re-allocating another 500MB of memory
for the second call would waste time.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list