classification
Title: OrderedDict prevents garbage collection if a circulary referenced class is used as key
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Tim.Graham, charettes, eric.snow, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-12-23 23:39 by charettes, last changed 2016-01-19 13:50 by serhiy.storchaka. 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
2016-01-19 13:50:20serhiy.storchakasetstatus: open -> closed
messages: + msg258592

assignee: serhiy.storchaka
resolution: fixed
stage: patch review -> resolved
2016-01-19 12:49:09python-devsetnosy: + python-dev
messages: + msg258590
2015-12-28 21:49:14serhiy.storchakasetfiles: + odict_traverse.patch
versions: + Python 3.6
messages: + msg257130

keywords: + patch
stage: patch review
2015-12-28 13:02:36berker.peksagsetnosy: + eric.snow, serhiy.storchaka
2015-12-28 12:59:41Tim.Grahamsetnosy: + Tim.Graham
2015-12-23 23:39:59charettescreate