A couple garbage collector questions

Douglas Alan nessus at mit.edu
Mon Apr 2 23:44:13 EDT 2001


Neil Schemenauer <nas at python.ca> writes:

> Douglas Alan wrote:
> >   (1) Why does it use the rather unusual algorithm it does, rather
> >       than a more typical mark and sweep?  The per-object storage cost
> >       for the extra reference count is surely greater than the bit or
> >       two required for a typical mark and sweep.

> Mark and sweep requires that you find all root pointers.  That's
> difficult to do if you want it to be portable and allow for easy
> embedding and extension of the language.

Why doesn't the procedure that a C extension (or embedder) uses to
increment the reference count of a Python object just register such
objects as root objects?  The reference count decrementer would then
unregister such objects.

> >   (2) Why does the algorithm need back-pointers for the object chain?

> So that removing objects from the set is O(1).

In explaining to you why I didn't yet understand why you need
back-pointers, I figured it out.  (I.e. you have to remove objects
that you don't arrive at via walking down the list.)  Thanks!

|>oug



More information about the Python-list mailing list