Freeing memory

Steve Holden sholden at holdenweb.com
Thu Apr 25 10:02:36 EDT 2002


"Siegfried Gonzi" <siegfried.gonzi at kfunigraz.ac.at> wrote in message
news:3CC7F1F7.8B987146 at kfunigraz.ac.at...
> The topic has emerged quite often in the past but never completely
> answered.
>
> I have an application which consumes at every run 60MB RAM. Every new
> start of the script ('Run scipt') augments the memory up to old_memory +
> 60MB. After a few runs I am at 400MB.
>
> I always just thought Python has a garbage collector and will dispose
> the memory after the last reference (for me this means: end of my
> script).
>
> In Clean or Common Lisp or R-language or Yorick I never had any dire
> need to
> consult the Windows Task-Manager. The explanation that Python really
> gets rid of the memory but the Windows OS does not show it sounds a
> little bit strange to me.
>
> I am now a little bit more accustomed to Python, but I cannot imagine to
> use it further for larger projects. My machine has got 256MB RAM and I
> just use Windows XP (80MB RAM) and Python2.2; there is absolutely no
> excuse
> for Python not to find any free successive memory block.
>
> There is the chance that  memory becomes free; but I am not willing to
> wait about 10 minutes (after a 10 minutes calculation) in order to see a
> possible disposing of memory. I want to start the second simulation
> right after the first, but after a few simulations I end up at 400MB and
> Python chrashes.
>
>
> Any suggestions?
>

It sounds as though you are running the successive simulations in a single
interactive editor session. Are you possibly doing something like (simulated
interpreter session follows):

>>> import simulator
>>> a = simulator.run("file1.txt")
>>> b = simulator.run("file2.txt")
>>>

or the like? If so then the references in variables might account for the
memory usage. Would it be possible to rewrite your code so you could do
simulation runs from the command line, along the lines of

python simulate file1.txt

In this case there is no chance that the interpreter would continue to hold
on to memory used by previous simulation runs -- when it terminates, the OS
gets the memory back, period.

Python is usually a reliable consumer of memory, and a reliable collector of
garbage (although a few pathological cases have been observed). You are
seeing the behavior you describe because the interpreter is somehow
retaining pointers to the data structures created during your simulations.
Without a bit more information about the program structure and your usage
it's difficult to say what might really be causing your problem.

regards
 Steve
--

home: http://www.holdenweb.com/
Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list