function attributes are like function objects
Fredrik Lundh
fredrik at effbot.org
Wed Feb 7 02:19:23 EST 2001
Scottie wrote:
> The dictionary (a in your example) will force a reference to the function to
> exist, thus preventing it from being collected.
That dictionary sits inside a *class* object. That class
also holds references to the function objects, as well as
to the dictionary. No cycles here.
> > - requires one dictionary per type of method attribute.
Which is a problem only if you have more attributes than
methods in your classes, of course. Not very likely.
(and easy to solve with a global attribute dictionary)
> - prevents funtions referenced from being garbage collected.
Which is a problem only if you spend a lot of time adding and
removing methods from classes. Not very likely.
(and easy to solve with a weak dictionary, or by changing
to a better design)
Cheers /F
More information about the Python-list
mailing list