Python memory deallocate

H

Heiko Wundram

Am Donnerstag 11 Mai 2006 18:07 schrieb Michele Petrazzo:
This isn't true. Just tried with python 2.5a2 and:

d:\python25\python.exe


So now, like you saied, if I try to allocate another memory chunk,

python'll re-use it... But this isn't true:

Do why python don't reuse the freed memory and re-allocate 4 MB (126 -
122)?

What the OS reports as the memory usage isn't actually what's allocated by
Python objects. As Tim Peters pointed out in another post, this number just
specifies the amount of memory the OS has given to libc, which in turn has
given it to Python.

Basically, what you're seeing is exactly the reuse of memory that Python
internally does. Why it allocates 4 more megabytes I wouldn't know, but as
you can see, the range b is actually 19 megabytes in size (a little smaller,
but >10MB), whereas it only takes up 4 megabytes when you construct it after
you deleted the old list. That's a major difference.

I just tried the following:

modelnine@phoenix ~ $ python
Python 2.4.3 (#1, May 4 2006, 23:51:29)
[GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1000 7836 0.0 0.3 15816 3540 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 3.8 47656 35388 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 2.9 39840 27572 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 3.8 48720 35460 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 2.9 40904 27644 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 3.8 48720 35460 pts/1 S+ 15:09 0:00 python

1000 7836 0.2 2.9 40904 27644 pts/1 S+ 15:09 0:00 python

....

Ad infinitum (see the pattern?)

Convinced now that Python reuses memory? (see the sixth column for actual
memory usage, the fifth is mapped memory, which contains shared libraries,
etc.) The list is about 32MB in size (see the initial jump from 3MB to 35MB),
but only adds about 8MB in each iteration, which are freed in each run.

--- Heiko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top