How do I really delete an imported module?

Terry Reedy tjreedy at udel.edu
Mon Dec 22 12:07:14 EST 2003


"Peter Otten" <__peter__ at web.de> wrote in message
news:bs6dtv$9vn$05$1 at news.t-online.com...
> >> What is the pythonic way to completely delete
a module and get it's
> >> memory garbage collected?
>
> The pythonic way is probably not to bother :-)

Yes.  A module object with an empty dict is not
big enough (on the order of 100 bytes + __name__)
to worry about on almost any modern machine.  Even
if the attached class, function, and code objects
take 10 or even 100 K, that is often not enough to
fuss over (and if it is and they will not be
needed again, delete).  If a module creates a
large multimegabyte private object, it should be
either temporary or explicitly deleteable.

Terry J. Reedy






More information about the Python-list mailing list