why does memory consumption keep growing?

Chris Angelico rosuav at gmail.com
Fri Oct 6 07:35:45 EDT 2017


On Fri, Oct 6, 2017 at 8:05 PM, D'Arcy Cain <darcy at vybenetworks.com> wrote:
> On 10/05/2017 05:42 PM, Fetchinson . via Python-list wrote:
>>
>> On 10/5/17, Chris Angelico <rosuav at gmail.com> wrote:
>>>
>>> On Fri, Oct 6, 2017 at 8:06 AM, Fetchinson . via Python-list
>>> <python-list at python.org> wrote:
>>>>
>>>>      import mystuff
>>>>      mystuff.some_more_expensive_stuff( x )
>>>>      del mystuff
>>>>      del x
>>>
>>> You're not actually deleting anything. When you say "del x", all
>>> you're doing is removing the *name* x. Especially, deleting an
>>> imported module basically does nothing; it's a complete waste of time.
>>> Modules are kept in their own special cache.
>>
>>
>> Meaning that if mystuff has some leaky stuff in it, there is no way
>> for me to recover?
>
>
> Even if deleting mystuff actually removed it the objects that it created
> would still exist.  Import mystuff once at the top of your script. Importing
> over and over just costs CPU and could, in fact, be contributing to your
> leak.

Importing an already-imported module is as simple as:

mystuff = sys.modules["mystuff"]

So it's not contributing to the leak, but it's also not helping anything.

ChrisA



More information about the Python-list mailing list