Python 2.0

Graham Matthews graham at sloth.math.uga.edu
Thu Jun 3 17:17:59 CEST 1999


Paul Prescod <paul at prescod.net> wrote:
> Is there a language with real GC where destructors are called as
> predictably as they are in Python?
salvador at my-deja.com wrote:
: No, but it could be done in Python, GC isn't incompatible with reference
: counting and both can be combined. A simple GC could be added just to
: detect ciclical data structures and remove it
: 
: Even new special obect methods could be suported by the language to
: handle it, say __gc__, that gets called by the GC requesting the object
: to liberate its references to other objects so the ciclid data breaks.

You don't need a new method call -- all you need is a mark and sweep
collector with refcounts. I really am amazed that this has generated so
much traffic. It's very simple. You have ref counts just like you do
now in Python. When an objects refcount goes to 0 its __del__ method
is called. On top of this you add a mark and sweep collector to handle
circular references. During a sweep if it finds dead objects it calls
the __del__ method for that object. Why is this approach to memory
management any more problematic than the current approach? Of course
you need to have a way of registering roots and traversing foreign
objects, and of allocating non compactable blocks, but these are all
totally standard things.

graham
-- 
                          So I turned around
                    And 40,000 headmen bit the dirt
                      Firing twenty shotguns each
                        And man it really hurt




More information about the Python-list mailing list