newbie question - remove a module from ram

john fabiani jfabiani at yolo.com
Mon May 10 13:02:19 EDT 2004


Paul McGuire wrote:
> "Peter Otten" <__peter__ at web.de> wrote in message
> news:c7nvr1$fsc$01$1 at news.t-online.com...
> 
>>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
>>
> 
> So then what if he follows up with:
> 
>     del sys.modules["random"]
> 
> Are there any other dangling references to this module that would stymie the
> garbage collector (assuming that the OP hasn't saved off his own reference
> to the module)?
> 
> -- Paul
> 
> 
I think I follow:  but doesn't the garbage collector decide what is to 
be done?   Assuming that there were no dangling references wouldn't the 
ram be available for re-use?
John



More information about the Python-list mailing list