Garbage collection (was: how to "free" an object/var ?)

Ben Finney bignose+hates-spam at
Wed Jan 31 01:10:46 CET 2007

Stef Mientki <S.Mientki-nospam at> writes:

> If I create a large array of data or class, how do I destroy it
> (when not needed anymore) ?

Python comes with garbage collection, which is enabled by default.
Some time after your code stops needing the object, the garbage
collector will clean it up.

To check whether your Python has garbage collection enabled, you can
use the 'gc' interface module:

    Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
    >>> import gc
    >>> gc.isenabled()
    >>> help(gc)

This module is only needed if you want to *interact* with the garbage
collector, which you won't unless you want to tune it or turn it off.

 \          "Immorality: The morality of those who are having a better |
  `\                                       time."  -- Henry L. Mencken |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list