Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderedDict prevents garbage collection if a circulary referenced class is used as key #70123

Closed
charettes mannequin opened this issue Dec 23, 2015 · 4 comments
Closed
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@charettes
Copy link
Mannequin

charettes mannequin commented Dec 23, 2015

BPO 25935
Nosy @ericsnowcurrently, @serhiy-storchaka, @charettes, @timgraham
Files
  • test.py: Reproduction test case
  • odict_traverse.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-01-19.13:50:20.825>
    created_at = <Date 2015-12-23.23:39:59.235>
    labels = ['extension-modules', 'type-bug']
    title = 'OrderedDict prevents garbage collection if a circulary referenced class is used as key'
    updated_at = <Date 2016-01-19.13:50:20.824>
    user = 'https://github.com/charettes'

    bugs.python.org fields:

    activity = <Date 2016-01-19.13:50:20.824>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-01-19.13:50:20.825>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2015-12-23.23:39:59.235>
    creator = 'charettes'
    dependencies = []
    files = ['41399', '41441']
    hgrepos = []
    issue_num = 25935
    keywords = ['patch']
    message_count = 4.0
    messages = ['256945', '257130', '258590', '258592']
    nosy_count = 5.0
    nosy_names = ['python-dev', 'eric.snow', 'serhiy.storchaka', 'charettes', 'Tim.Graham']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25935'
    versions = ['Python 3.5', 'Python 3.6']

    @charettes
    Copy link
    Mannequin Author

    charettes mannequin commented Dec 23, 2015

    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 bpo-25410.

    @charettes charettes mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Dec 23, 2015
    @serhiy-storchaka
    Copy link
    Member

    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).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 19, 2016

    New changeset 627575e9a7aa by Serhiy Storchaka in branch '3.5':
    Issue bpo-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 bpo-25935: Garbage collector now breaks reference loops with OrderedDict.
    https://hg.python.org/cpython/rev/5f0a08cfc4f6

    @serhiy-storchaka
    Copy link
    Member

    In some cases (as in committed test) garbage collector was not able to collect a loop with OrderedDict at all.

    @serhiy-storchaka serhiy-storchaka self-assigned this Jan 19, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant