Python leaks in cyclic garbage collection
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Feb 19 00:40:41 EST 2011
On Fri, 18 Feb 2011 20:49:09 -0800, Chris Rebert wrote:
> And following the pointer to gc.garbage's docs:
> http://docs.python.org/library/gc.html#gc.garbage : "Objects that have
> __del__() methods and are part of a reference cycle ***cause the entire
> reference cycle to be uncollectable*** [...] Python doesn’t collect such
> cycles automatically because, in general, it isn’t possible for Python
> to guess a safe order in which to run the __del__() methods. [...] It’s
> generally better to avoid the issue by not creating cycles containing
> objects with __del__() methods"
Another solution is to manually break the cycle, perhaps by providing a
"close" method, and requiring the caller to use it.
--
Steven
More information about the Python-list
mailing list