[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: gc: Lua vs. Python
- From: Hisham <hisham.hm@...>
- Date: Mon, 20 Oct 2008 03:33:25 -0200
On Sun, Oct 19, 2008 at 10:39 AM, Enrico Colombini <firstname.lastname@example.org> 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
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
>>> sys.foo = "hello"
>>> sys = None
>>> import sys
This was written late 2006 (at the time of Python 2.4.3); things may
have changed since then.