Message188875
| Author |
kristjan.jonsson |
| Recipients |
kristjan.jonsson |
| Date |
2013年05月10日.20:22:22 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1368217344.29.0.260515184231.issue17950@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Classes contain two kinds of cycles back to themselves:
1) in their __mro_ list, the class itself is typically the first member.
2) in the descriptors for various fields such as __dict__.
The problem here is that there is no way to break the cycle. A class that is dynamically created (e.g. in a function) and then not needed, will stick around until garbage collection is performed.
This happens in spite of attempts within the core to avoid such cycles. For instance, the type's tp_subclasses list contains to avoid a cycle between a baseclass and its parent.
A .py file demonstrating the problem is attached.
A patch is attached that resolves the issue:
1) the mro tuple in the type object is "nerfed" to contain a Py_None reference in its first place, where it previously held the cyclic reference to the type object itself. This is then "fixed" in place where required. the __mro__ attribute becomes a getter that duplicates the tuple.
2) the descriptors are modified to hold a weak-reference to the target type, rather than a strong reference.
3) Fix process cleanup. The thread state cannot be released until after the cleanup of e.g. PySet_Fini() because the freeing of objects in there requires the DUSTBIN_SAFE macros that require the thread state. Cleanup behaviour probably changed since objects go away on their own now.
4) changes to test_gc.py in the testsuite reflecting the changed behaviour
The patched code passes all the testsuite. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2013年05月10日 20:22:24 | kristjan.jonsson | set | recipients:
+ kristjan.jonsson |
| 2013年05月10日 20:22:24 | kristjan.jonsson | set | messageid: <1368217344.29.0.260515184231.issue17950@psf.upfronthosting.co.za> |
| 2013年05月10日 20:22:24 | kristjan.jonsson | link | issue17950 messages |
| 2013年05月10日 20:22:24 | kristjan.jonsson | create |
|