module imports and memory usage

Istvan Albert ialbert at
Tue Nov 30 16:17:47 CET 2004

Brad Tilley wrote:

> Also, is there a way to load and unload modules as they are needed. I 
> have some scripts that sleep for extended periods during a while loop 
> and I need to be as memory friendly as possible. I can post a detailed 
> script that currently uses ~ 10MB of memory if anyone is interested.

I believe that the rule of thumb for Python, C, Java
and probably most other portable languages is that
freed memory cannot be released back to the
operating system. The best you can expect (usually true)
is  that allocating the same amount later will not
increase the memory footprint.

So the only way to write memory efficient programs
might be to:
  1. either not load all the data
  2. run the data intensive routines as a separate process
that terminates and exists


More information about the Python-list mailing list