[Python-Dev] Documentation about Python's GC, python-dev list messages referenced in Modules/gcmodule.c not reachable anymore

"Martin v. Löwis" martin at v.loewis.de
Thu Dec 8 09:52:18 CET 2005


Tim Peters wrote:
> Python-style refcounting isn't generally a good approach either when
> real-time constraints must be met:  when a refcount on an object P
> falls to 0, not only does the interpreter "pause" to reclaim P, but
> also to reclaim all the objects that were reachable only from P.

Sure - but that still allows for meeting real-time constraints.
You need to understand, or estimate, the worst-case execution time
that any statement may have. In general, any assignment in Python
could trigger releasing many objects, as the old value is released.

In a specific program, analysis is much brighter. You *know* what
variables carry references to huge data structures, and you *know*
where these variables are assigned to. Also, you can often give
an upper bound to the number of objects that may get released in
the worst case if you assign to a variable.

This is different from garbage collection: it is generally very
difficult to predict when precisely the garbage collector will
be invoked; in the current Python implementation, you would have
to predict at what point in the code you hit the 1000 objects
quota. This is nothing that can be learned from local inspection,
and thus hard to tell.

For a real time system, it is not just important that all
actions complete fast. Instead, it is important to tell what
statements might be long-running, and how long. In Python's
reference counting, this is possible, hence it is (IMO)
suitable for real-time purposes.

Regards,
Martin


More information about the Python-Dev mailing list