Message76820
But the garbage collector was invented for this very purpose: to break
cycles! Take the following example which create a cycle for every
instance of the class (the profile module has similar code):
class C:
def __init__(self):
self.action = self.action_GO
# cycle: the object's dict now contains a bound method
# which references the object
def action_GO(self):
print("GO")
This kind of construct is useful, and probably the best one in some
cases. Would you ban it from your code? from the python standard library?
Reference cycles are not bad at all, as long as they only hold memory:
they will be reclaimed when the systems needs more memory.
I agree that they can be a problem for other valuable resource: opened
files, sockets, database cursors... even one thousand of uncollected
sockets are not enough to trigger a collection.
For this usage, I suggest that you iterate over gc.garbage, only warn
for such objects and remove all others (and after, clear gc.garbage and
run gc.collect() without the debug flag) |
|
Date |
User |
Action |
Args |
2008-12-03 09:53:04 | amaury.forgeotdarc | set | recipients:
+ amaury.forgeotdarc, wplappert, darrenr |
2008-12-03 09:53:04 | amaury.forgeotdarc | set | messageid: <1228297984.45.0.482783144125.issue4273@psf.upfronthosting.co.za> |
2008-12-03 09:53:03 | amaury.forgeotdarc | link | issue4273 messages |
2008-12-03 09:53:02 | amaury.forgeotdarc | create | |
|