Safe doubly-linked list/tree implementation?

Lars Damerow lars at pixar.com
Tue Sep 5 19:01:13 EDT 2000


Hi folks!

I'm trying to come up with an implementation of a doubly-linked tree (where the
children have links to their parents) that doesn't leak memory due to reference
cycles.  It's such a simple data structure that I feel a bit foolish asking,
but...

The FAQ says that in the case of doubly-linked structures, reference cycles
must be explicitly broken in order to avoid memory leakage.  I thought that I
could use __del__ to do this, but __del__ only seems to be called when the
reference count reaches zero.

Does anyone know of an implementation that's already floating around out there?
If not, are there any recommendations for a good approach to making this type
of data structure?

Thanks!
-lars

___________________________________________________________
lars damerow
pixar animation studios
technomonkey
lars at pixar.com

"Nauseous.  Nauseated.  The first means 'sickening to contemplate'; the second
means 'sick at the stomach.'  Do not, therefore, say, "I feel nauseous," unless
you are sure you have that effect on others."

- William Strunk Jr., "The Elements of Style"





More information about the Python-list mailing list