[Python-Dev] recursive closures - reference leak (original) (raw)

Hrvoje Niksic hrvoje.niksic at avl.com
Tue Dec 8 14:52:06 CET 2009


Kristján Valur Jónsson wrote:

The problem with this is that once you have called factorial() once, you end up with a recursive cycle. „factorial“ has become a cell object, referencing the „helper“ function, which again refers to the outer cell object. This requires „gc“ to clean up. Also, it is entirely non-obvious. the problem becomes worse if the inner function also refers to some large, temporary variable, since it will get caught up in the reference loop.

What problem are you referring to? Python has a gc exactly to deal with situations like this one. Surely you are aware that the cycle collector is invoked automatically without requiring user intervention. What specific issue are you trying to work around?



More information about the Python-Dev mailing list