Are reference cycles bad form?

Manuel M Garcia mail at
Sun Apr 20 01:12:42 CEST 2003

On Sat, 19 Apr 2003 11:16:10 -0600, Steven Taschuk
<staschuk at> wrote:

>Imho this is an engineering question, not a style question.  It's
>a trade-off between the benefits of the algorithms you can write
>when the data structure has reference cycles and the slightly
>inferior garbage collection properties of such structures.  The
>right trade-off to make depends on the circumstances.

In my current case, it feels more like a style question, instead of an
engineering question.  My typical Python program at work is swamped by
accessing a database over the network, so even if my algorithms ran
infinitely fast, it would only take off a small percentage of the
whole runtime.  And since I am working in Windows, my memory usage is
a small fraction of what Windows requires to display my desktop
wallpaper, 32-bit color icons, anti-aliased fonts, etc.

If I am coding in C, reference cycles don't bother me, because I have
to clean up everything anyway.  But when I am using a language that
does memory management for me, I am prejudiced against creating any
reference cycles.  Probably irrationally prejudiced, undoubtedly
because of the years I coded in Visual Basic and older versions of
Python, which could not reclaim memory in a reference cycle.

Happily, Python code is easy to refactor, so I am more likely in
Python to experiment with different data structures and algorithms,
and pick the one that feels 'cleanest'.


More information about the Python-list mailing list