[Python-Dev] Re: A surprising case of cyclic trash
Neil Schemenauer
nascheme@enme.ucalgary.ca
Tue, 4 Apr 2000 23:19:45 -0600
An even simpler example:
>>> import sys
>>> d = {}
>>> print sys.getrefcount(d)
2
>>> exec("def f(): pass\n") in d
>>> print sys.getrefcount(d)
3
>>> d.clear()
>>> print sys.getrefcount(d)
2
exec adds the function to the dictionary. The function
references the dictionary through globals.
Neil
--
"If elected mayor, my first act will be to kill the whole lot of
you, and burn your town to cinders!" -- Groundskeeper Willie