newbie question - remove a module from ram

Peter Otten __peter__ at web.de
Mon May 10 09:24:49 EDT 2004


Paul McGuire wrote:

> "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?
>> John
> 
> Well, you were pretty close with calling something like .release().  Use
> the del statement.
> 
>>>> import random
>>>> print random.random()
> 0.475899061786
>>>> del random
>>>> print random.random()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'random' is not defined
>>>>

and then

>>> import sys
>>> sys.modules["random"].random()
0.43459738002826365
>>>

should make it clear that (next to) no memory is freed in the process.

Peter




More information about the Python-list mailing list