Re: Python memory handling
- From: "Josh Bloom" <joshbloom@xxxxxxxxx>
- Date: Thu, 31 May 2007 08:29:04 -0700
If the memory usage is that important to you, you could break this out
into 2 programs, one that starts the jobs when needed, the other that
does the processing and then quits.
As long as the python startup time isn't an issue for you.
On 31 May 2007 04:40:04 -0700, frederic.pica@xxxxxxxxx
<frederic.pica@xxxxxxxxx> wrote:
Greets,.
I've some troubles getting my memory freed by python, how can I force
it to release the memory ?
I've tried del and gc.collect() with no success.
Here is a code sample, parsing an XML file under linux python 2.4
(same problem with windows 2.5, tried with the first example) :
#Python interpreter memory usage : 1.1 Mb private, 1.4 Mb shared
#Using http://www.pixelbeat.org/scripts/ps_mem.py to get memory
information
import cElementTree as ElementTree #meminfo: 2.3 Mb private, 1.6 Mb
shared
import gc #no memory change
et=ElementTree.parse('primary.xml') #meminfo: 34.6 Mb private, 1.6 Mb
shared
del et #no memory change
gc.collect() #no memory change
So how can I free the 32.3 Mb taken by ElementTree ??
The same problem here with a simple file.readlines()
#Python interpreter memory usage : 1.1 Mb private, 1.4 Mb shared
import gc #no memory change
f=open('primary.xml') #no memory change
data=f.readlines() #meminfo: 12 Mb private, 1.4 Mb shared
del data #meminfo: 11.5 Mb private, 1.4 Mb shared
gc.collect() # no memory change
But works great with file.read() :
#Python interpreter memory usage : 1.1 Mb private, 1.4 Mb shared
import gc #no memory change
f=open('primary.xml') #no memory change
data=f.read() #meminfo: 7.3Mb private, 1.4 Mb shared
del data #meminfo: 1.1 Mb private, 1.4 Mb shared
gc.collect() # no memory change
So as I can see, python maintain a memory pool for lists.
In my first example, if I reparse the xml file, the memory doesn't
grow very much (0.1 Mb precisely)
So I think I'm right with the memory pool.
But is there a way to force python to release this memory ?!
Regards,
FP
--
http://mail.python.org/mailman/listinfo/python-list
- Follow-Ups:
- Re: Python memory handling
- From: Matthew Woodcraft
- Re: Python memory handling
- From: frederic . pica
- Re: Python memory handling
- References:
- Python memory handling
- From: frederic . pica
- Python memory handling
- Prev by Date: Re: How to clean a module?
- Next by Date: Re: How to parse usenet urls?
- Previous by thread: Re: Python memory handling
- Next by thread: Re: Python memory handling
- Index(es):
Relevant Pages
|