![](https://secure.gravatar.com/avatar/7c721b6de34c82ce39324dae5214dbf8.jpg?s=120&d=mm&r=g)
[Tim]
...
Anyone have a bright idea? It's remarkable how long we've managed to go without noticing that everything is disastrously broken here <0.9 wink>.
[Jim]
Sure. Clearing cyclic trash can call Python code. If there are weakrefs to any of the cyclic trash, then those wekrefs can be used to resurrect the objects. Therefore, *before* clearing cyclic trash, we need to remove any weakrefs. If any of the weakrefs being removed have callbacks, then we need to save the callbacks and call them *after* all of the weakrefs have been cleared.
Thanks! Neil Schemenauer and I got together today, and talked each other into believing this can be made to work, and that it's likely the best solution too. The devil's in the details, but this a generalization of the last round of weakref vs. gc bugfixes, which got the effect of what you suggest here except only for cyclic-trash weakref objects with weakref callbacks. It needs generalization to all weakly-referenced cyclic-trash objects. Still unsure how hard that will be to code up, but am sure it will fix all the test cases I concocted.