msg75582 - (view) |
Author: (darrenr) |
Date: 2008-11-06 21:58 |
The profile module creates a reference cycle. See attached session. |
|
|
msg75583 - (view) |
Author: (darrenr) |
Date: 2008-11-06 22:04 |
The profile module creates a reference cycle. See attached session. Note: cycle can be broken by deleting reference to 'dispatcher' on profile.Profile() instance. |
|
|
msg75604 - (view) |
Author: Winfried Plappert (wplappert) |
Date: 2008-11-07 14:47 |
I tested profile_cycle.txt on both Python 2.5.2 and Python 2.6. The cycle you are showing for release 2.4.1 cannot be seen on both releases. Why dont't you try and upgrade to Python 2.6? |
|
|
msg75608 - (view) |
Author: Benjamin Peterson (benjamin.peterson) *  |
Date: 2008-11-07 17:53 |
Let's mark this as out of date then. |
|
|
msg75609 - (view) |
Author: (darrenr) |
Date: 2008-11-07 18:35 |
Issue also occurs in 2.6. Note that it only shows up if gc is set to save all cycles. |
|
|
msg76802 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2008-12-02 23:16 |
Where is the problem, if these reference cycles are properly broken by the garbage collector *unless* you tell it not to? |
|
|
msg76811 - (view) |
Author: (darrenr) |
Date: 2008-12-03 04:09 |
I work at a development house that has decided to tell gc to keep all cycles, in order to prevent any cycles from being created at all. It's analogous to the policy of keeping a C++ build warning-free. |
|
|
msg76820 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2008-12-03 09:53 |
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) |
|
|
msg76918 - (view) |
Author: (darrenr) |
Date: 2008-12-04 19:17 |
We've gotten into the habit of writing manual destructors to remove references like the one you wrote. I think explicit destruction is a useful paradigm when resource allocation is involved and it's important to manage the allocation's lifetime closely. However you've convinced me that it's OK to allow these types of reference cycles, and to make an effort to clean up only cycles involving instances with __del__ methods. I've been able to convince the team. Thanks for helping to clear this up. |
|
|
msg76930 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2008-12-04 21:48 |
Closing issue as "Not a bug". (but we can continue the discussion here...) |
|
|
msg77990 - (view) |
Author: (darrenr) |
Date: 2008-12-17 22:20 |
I think we still need to prevent collectable cycles in our Python code. Here's the situation: We've got a process that creates many Python objects, and it needs to be responsive, it's not good for it to block on one operation for more than 100-200 ms. The automatic garbage collection is currently taking on the order of 2 seconds for this process. If we can guarantee that no collectable or non-collectable cycles are being created, we can gradually increase the collection threshold, or turn off the garbage collector entirely, reducing or eliminating the blocking overhead of garbage collection. |
|
|