1 Title: The Python's algorithm
2 Tags: en, d, dgc, rc, cycles, python
4 Python__ (at least CPython__) uses reference counting, and since version 2.0 it
5 includes a `cycles freeing algorithm`__. It uses a generational approach, with
8 __ http://www.python.org/
9 __ http://en.wikipedia.org/wiki/CPython
10 __ http://arctrix.com/nas/python/gc/
12 Python makes a distinction between *atoms* (strings and numbers mostly), which
13 can't be part of cycles; and *containers* (tuples, lists, dictionaries,
14 instances, classes, etc.), which can. Since it's unable to find all the roots,
15 it keeps track of all the container objects (as a double linked list) and
16 periodically look in them for cycles. If somebody survive the collection, is
17 promoted to the next generation.
19 I think this works pretty well in real life programs (I never had problems with
20 Python's GC -long pauses or such-, and I never heard complains either), and
21 I don't see why it shouldn't work for D. Even more, Python have an issue with
22 finalizers which don't exist in D because you don't have any `warranties about
23 finalization order in D`__ already (and nobody seems to care, because when you
24 need to have some order of finalization you should probably use some kind of
27 __ http://www.digitalmars.com/d/1.0/class.html#Destructor
28 __ http://www.digitalmars.com/d/1.0/memory.html#raii
30 .. vim: set et sw=4 sts=4 :