Re: Python memory handling



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

.



Relevant Pages

  • Re: Python memory handling
    ... it to release the memory? ... I've tried del and gc.collectwith no success. ... import gc #no memory change ... Prior to Python 2.5, arenas were never ...
    (comp.lang.python)
  • Re: Python memory handling
    ... it to release the memory? ... import gc #no memory change ... del data #meminfo: 11.5 Mb private, ... python maintain a memory pool for lists. ...
    (comp.lang.python)
  • Python memory handling
    ... I've some troubles getting my memory freed by python, ... I've tried del and gc.collectwith no success. ... import gc #no memory change ...
    (comp.lang.python)
  • Re: StackOverflowException.
    ... The Status object monitors the ... so I'm really at a total loss as to where I'm leaking stack memory. ... private static extern bool EscapeCommFunction(IntPtr hFile, ... Good to know about arrays. ...
    (microsoft.public.dotnet.framework)
  • Re: How: multiple program instances sharing same data
    ... so this memory isn't shared. ... private copy of JITted code. ... Ok, because the .exe isn't native to my machine, it gets just-in-time ... I am talking about a Windows NET App, ...
    (microsoft.public.dotnet.languages.csharp)