Issue 25935: OrderedDict prevents garbage collection if a circulary referenced class is used as key (original) (raw)

Issue25935

Created on 2015-12-23 23:39 by charettes, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py charettes,2015-12-23 23:39 Reproduction test case
odict_traverse.patch serhiy.storchaka,2015-12-28 21:49 review
Messages (4)
msg256945 - (view) Author: Simon Charette (charettes) * Date: 2015-12-23 23:39
I attached a file with a reproduction test case that passes on Python 2.7 and 3.4 but fails on 3.5.0 and 3.5.1 This might be solved by the improvement planed in #25410.
msg257130 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-28 21:49
An OrderedDict owns two references to every key (as a dict and from a linked list). Therefore it should visit it twice in tp_traverse. Proposed patch fixes garbage collection for OrderedDict. It also rewrites OrderedDict clearing in more reentrant form (a linked list is detached from an OrderedDict before deallocating its nodes that can trigger executing user code).
msg258590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-19 12:49
New changeset 627575e9a7aa by Serhiy Storchaka in branch '3.5': Issue #25935: Garbage collector now breaks reference loops with OrderedDict. https://hg.python.org/cpython/rev/627575e9a7aa New changeset 5f0a08cfc4f6 by Serhiy Storchaka in branch 'default': Issue #25935: Garbage collector now breaks reference loops with OrderedDict. https://hg.python.org/cpython/rev/5f0a08cfc4f6
msg258592 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-19 13:50
In some cases (as in committed test) garbage collector was not able to collect a loop with OrderedDict at all.
History
Date User Action Args
2022-04-11 14:58:25 admin set github: 70123
2016-01-19 13:50:20 serhiy.storchaka set status: open -> closedmessages: + assignee: serhiy.storchakaresolution: fixedstage: patch review -> resolved
2016-01-19 12:49:09 python-dev set nosy: + python-devmessages: +
2015-12-28 21:49:14 serhiy.storchaka set files: + odict_traverse.patchversions: + Python 3.6messages: + keywords: + patchstage: patch review
2015-12-28 13:02:36 berker.peksag set nosy: + eric.snow, serhiy.storchaka
2015-12-28 12:59:41 Tim.Graham set nosy: + Tim.Graham
2015-12-23 23:39:59 charettes create