[Python-Dev] reference leaks, del, and annotations (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 31 04:21:13 CEST 2006


Jim Jewett wrote:

The checkins list has been struggling with generator reference leaks; the latest conclusion was that some are unavoidable because of del cycles. That sort of defeats the purpose of resource managers.

Seems to me we need a whole new approach to finalization that's friendly to cyclic gc, such as a way of registering a finalizer that doesn't depend on the original object.

If such a mechanism were available, could it be used instead of a del method to clean up after a generator? (I'm asking because I'm not sure exactly what a generator del needs to do.)

As a strawman proposal:

deletes = [(obj.del.cycle, obj) for obj in cycle if hasattr(obj, "del") and hasattr(obj.del, "cycle")] deletes.sort() for (cycle, obj) in deletes: obj.del()

I think we need to be very careful about doing anything like this. From what Tim said recently, the consequences of an object getting its del annotation wrong could be as bad as crashing the interpreter.

-- Greg



More information about the Python-Dev mailing list