
* A closure must only keep alive the varables it references, not the whole pad on which they are allocated (Python messed up here)
Getting off subject, but I didn't know this about python. I'm not
saying you're incorrect, but my experimentation shows:
% cat t.py
class A(object):
def __init__(self, name): self.name = name
def __del__(self): print self.name, 'gone'
def f():
x = A('x')
y = A('y')
def g():
print x.name, 'alive'
return g
% python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import t
g = t.f()
y gone
g()
x alive
g.func_closure
#-> (