Upper memory limit

Michael Gilfix mgilfix at eecs.tufts.edu
Tue May 14 13:42:55 EDT 2002


On Tue, May 14 @ 19:15, Siegfried Gonzi wrote:
> Python disposes the memory after completing the calculation (I can see
> it in the task manager). But nobody has answered my question: Is Python
> just a garbage collector or a garbace collector *and* remover?

  Python does two things: Reference counting (removal after reference
has expired) and garbage collection; implementing clean up at
appropriate intervals. The mix of the two approaches is often the
best way of approaching memory management in terms of complexity
and obtrusiveness to program execution.

> The hint: reboot your Krempel every hour does not always work. In the
> afternoon I started a calculation at about 3 pm. I am sitting (in the
> meantime I have even successfully installed Linux) still here and wait
> until the calculation comes to an end (note: before I fired up the
> calculation I  rebooted the system).

  Well, if you're going over 128M and into swap, it could slow stuff down
but I urge you to make sure that you're tackling the problem correctly.

> I cannot comprehend the following: As I wrote, I call 8 times the same
> function, and it is interesting to observe that the first call to the
> function takes about 10-15 minutes, the second call also 10-15minutes,
> but the successive calls become always longer and longer; after 4 hours
> I am at my 6. call and still waiting.

  Sounds like you have some side effects. If you don't feel that python
is freeing stuff correctly, try using 'del' to tell python to free
a variable explicitly.

> 
> I have to underline that I do not use any object oriented programming
> technique (I assume you meant this when you write "self"). I use simple
> functions. Okay I have to admit that I make heavy use of the following
> scheme:
> 
> def f(list,list2):
> 	erg = []
> 	for k in range( len(list) ):
> 		erg.append( function_on_list2( list2[j] ) )
> 	return erg

  There's a bug in this though. it should be 'list2[k]', not 'j'.
Perhaps that's your side-effect?

  Why not do something like this? Much more readable and less error
prone:

   erg = map (lambda x, f=function_on_list2: f(x), list2[:k])

  or with list comprehension if you prefer:

  erf = [ function_on_list2(x) for x in list2[:k] ]

  Must easier.

> 
> I find the above very readable (and often better in style than Numeric's
> idiosyncrasy).
> 
> I hope I can make the transition to Linux in the next few month (hoping
> that the installation on my laptop will succeed).

  Well, welcome to Linux :) But don't discard python on windows just yet.
It usually does the job.

                   -- Mike

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html





More information about the Python-list mailing list