Problem with garbage collection (sort of)

Michael Hudson mwh at python.net
Mon Aug 18 10:59:25 EDT 2003


frank at chagford.com (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:

 http://www.python.org/doc/current/ref/customization.html#l2h-175

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.

Cheers,
mwh

-- 
  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.                        -- http://www.jwz.org/gruntle/design.html




More information about the Python-list mailing list