lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Oct 19, 2008 at 10:39 AM, Enrico Colombini <> wrote:
> While discussing Lua with a colleague, I've been told that Python's gc has
> no limitations. I vaguely remembered otherwise, by my recollections could be
> out-of-date.

It does have limitations. Two bits from my dissertation:

"In spite of offering a cycle detection mechanism, Python is unable to
collect cycles whose objects contain finalizers implemented in Python
itself (__del__ methods); the only way to access those objects is then
through the garbage list in the 'gc' module. This module (accessible
to C through Python function calls using the C API) offers an
interface to the garbage collector, including 'enable' and 'disable'
functions, to activate and deactivate the garbage collector;
'collect', to run a collection; 'get_objects', which returns a list
containing all objects controlled by the collector (except the list
itself); 'get_referrers' and 'get_referents', which return the list of
object that refer or are referred by a given object -- these lists are
obtained using the 'tp_traverse' function, which may not point to all
objects actually reachable, or may still return objects in an invalid
state (such as objects in cycles that were not yet collected or
objects still not fully constructed) and therefore should be used only
for debugging purposes."

"Python, on its turn, does not provide API features for unloading
modules, but allows assigning None to the global referring the module.
The module can then be imported again, but the same instance, stored
internally by Python, will be returned. The following interactive
command-line session allows us to observe this behavior, which happens
both directly in Python as well as through the C API:

>>> import sys
>>> = "hello"
>>> sys = None
>>> import sys

This was written late 2006 (at the time of Python 2.4.3); things may
have changed since then.

-- Hisham