Unload Modules

Martin von Loewis loewis at informatik.hu-berlin.de
Mon Nov 13 15:29:44 CET 2000


Curtis Jensen <cjensen at bioeng.ucsd.edu> writes:

> I can't seem to find a clear answer on this, but how do I remove an
> imported module?  I have some C modules that I import, the modules only
> contain function calls.  However, they are pretty big, and I'd like to
> unload these modules after I am done with them, in order to save on
> memory.  I don't have the source for these modules.
> 
> How can I unload these modules from within Python?

You can't. Furthermore, doing so does not save any memory. Even if the
module is very large, it terms of code size, the code does not consume
any memory - at least it shouldn't on an advanced operating
system. Instead, the operating system should only load those pages
that are actually used, and discard them once they aren't anymore.

If your operating system is not that advanced, you may need to perform
linker tricks (such as preloading it to an address that is not in use
otherwise) to support demand-paging the module.

Regards,
Martin




More information about the Python-list mailing list