Problem with garbage collection (sort of)

Michael Hudson mwh at
Mon Aug 18 16:59:25 CEST 2003

frank at (Frank Millman) writes:

> The problem is that class a keeps a reference to class b (self.b) and
> class b keeps a reference to class a (self.p), so the reference counts
> do not go down to zero without some additional action.

Sure, but since 2.0, Python supplies that additional action
itself... the problems are the __del__ methods.  This must be
documented somewhere... ah, here:

though that's not totally clear.

Basically, a cycle will not be cleared if one of the objects making up
the cycle has a __del__ method.

Sometimes it is possible to arrange things so only "leaf" objects have
__del__ methods, then all this ceases to be a problem.


  I think my standards have lowered enough that now I think ``good
  design'' is when the page doesn't irritate the living fuck out of 
  me.                        --

More information about the Python-list mailing list