>>> l = []
>>> l.append(l)
>>> del l
The reference count for the list created is now one. However,
since it cannot not be reached from inside Python and cannot
possibly be used again, it should be considered garbage. In the
current version of Python, this list will never be freed.
Creating reference cycles is usually not good programming
practice and can almost always be avoided. However, sometimes
it is difficult to avoid creating reference cycles and other
times the programmer does not even realize it is happening. For
long running programs such as servers this is especially
troublesome. People do not want their servers to run out of
memory because reference counting failed to free unreachable
objects. For large programs it is difficult to find how
reference cycles are being created.
$ cd Python-1.5.2 $ patch -p1 < ../gc-malloc-cleanup.diff $ patch -p1 < ../gc-boehm.diff $ autoconf $ ./configure --with-gcThe patch assumes you have libgc.a installed somewhere so that linking with -lgc works (/usr/local/lib should be okay). If you don't have the library, download and install it before compiling. Currently the patch is only tested on Linux. It will probably work on other Unix machines as well. On my Linux machine, the GC version of Python passes all regression tests.