Garbage Collection

Martin von Loewis loewis at informatik.hu-berlin.de
Mon Jan 15 18:22:44 EST 2001


"Jens Vogelgesang" <jens.vogelgesang at de.bosch.com> writes:

> 1) How can I free used memory.
>     myHash = {}, del(myHash}

That is exactly the way. With 

del myHash

(no parentheses), the dictionary is immediately released.

> 2) Can I force a Garbage Collection??

You don't need to. Python garbage collections works with reference
counting, as soon as the reference count drops to zero, the object is
automatically released, and its memory is reclaimed.

The only exception are cyclic structures; to collect those, you can
force collection via gc.collect().

Regards,
Martin




More information about the Python-list mailing list