Skip to content

Reference leak for object with non-trivial finalizer #140958

@efimov-mikhail

Description

@efimov-mikhail

Bug report

Bug description:

If we put this code snippet to Lib/test/test_dict_user_leak.py

import unittest

class DictUser:
    def __init__(self, d: dict):
        self.d = d

    def __del__(self):
        self.d['a'] = DictUser(self.d)

class TestFinalizerLeak(unittest.TestCase):
    def test_dict_user(self):
        DictUser(dict())

if __name__ == '__main__':
    unittest.main()

then we can see leaks with the following command:
./python -m test -R 3:3 -v test_dict_user_leak

CPython versions tested on:

CPython main branch, 3.14, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions