newbie question - remove a module from ram
Terry Reedy
tjreedy at udel.edu
Mon May 10 13:10:27 EDT 2004
"john fabiani" <jfabiani at yolo.com> wrote in message
news:4AAnc.6791$dH5.4946 at newssvr27.news.prodigy.com...
> Hi,
>
> I believe I have good understanding of import but it occurred to me that
> I might want to remove an imported module. I.e I load a module into ram
> and I no longer need the module. Modules just stays in ram? In the
> windows world I would "thisform.release()" and the garbage collector
> would release the ram. So did I miss something or is there no release
> method. How about a method within a class like destroy()?
>
> I just got to believe it's there???? But where?
The delete statement, in general, directs the interpreter to delete the
association between a name or any other slot and the previously associated
object. Ditto for function locals at function return. It does not tell
the interpreter what to do with a object when its last association
disappears. If, for a particular implementation, it makes sense to talk of
the object being in 'deletable memory' (and, for humans, it hardly does,
nor would it for read-only machine memory, nor, possibly, for 'builtin'
modules), then the standard *allows* but does not *require* deletion.
CPython currently caches a reference to modules so that code like the
following won't tear down a module as it returns and have to rebuild it at
every call:
def sincos(x):
import math as m # for the purpose of this example, assume this is only
math import
return sin(x), cos(x)
Modules are sufficiently small, sufficiently expensive to set up, and
sufficiently often reused, that I has not been thought worthwhile to add a
modwipe function to countervail the cache effect, which itself was added to
countervail the usual CPython delete-object- with-last-reference behavior.
Terry J. Reedy
More information about the Python-list
mailing list