how do I get modules to stop eating memory

Steve Holden sholden at holdenweb.com
Mon Jul 2 10:57:23 EDT 2001


"Charles Harrison" <speedy911 at mindspring.com> wrote in message
news:6f78b8b.0107020626.38939858 at posting.google.com...
> I posted a message about a week ago asking about deleting modules from
> memory.  I got several replies with things that should work, but they
> didn't.  Here's the scenario that I've been trying:
>
> - open the python shell and import sys and any other module
>
> Python 1.5.2 (#1, Aug 25 2000, 09:33:37)  [GCC 2.96 20000731
> (experimental)] on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import sys
> >>> import BaseHTTPServer
>
> - I also run 'top' when im doing this to monitor the memory that
> python is using. The 2112 is the memory used after importing the 2
> modules.
>
> 22738 charriso   0   0  2112 2112  1380 S     0.0  1.6   0:00 python
>
> - Now I do what should unload the module 'BaseHTTPServer' and free the
> memory.
>
> >>> del BaseHTTPServer
> >>> del sys.modules['BaseHTTPServer']
>
> - And now top says that the memory usage is now 2120.
>
> 22738 charriso   0   0  2120 2120  1384 S     0.0  1.6   0:00 python
>
> - Prior to importing BaseHTTPServer the memory usage was 1432.
> Shouldn't Python's memory usage have gone down to that number, or at
> least down some?

While its usage might have gone down, this doesn't necessarily mean the
amount it's claiming from the operating system will have. Different
implementations have different strategies.

a) Even when you've deleted the module, that doesn't mean the garbage
collector has run and collected the used memory; and

b) Even after the GC collects it, you need to be sure that it will return
memory to the OS for your working set used memory size to go down.

regards
 Steve

--
http://www.holdenweb.com/








More information about the Python-list mailing list