This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients shihai1991, vstinner
Date 2020-03-24.13:26:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585056366.95.0.223309018439.issue40050@roundup.psfhosted.org>
In-reply-to
Content
Code extremely simplified:
---
import unittest
import sys
import _imp

class ModuleSpec:
    pass

class Tests(unittest.TestCase):
    def test_import_fresh(self):
        spec = ModuleSpec()
        spec.sys_weakref = sys.modules["_weakref"]
        spec.name = "_weakref"
        module = _imp.create_builtin(spec)
        module.__spec__ = spec
        sys.modules["_weakref"] = module
---

I still get a leak:
---
test_leak leaked [34, 34, 34] references, sum=102
test_leak leaked [11, 11, 11] memory blocks, sum=33
---

I understand that sys.modules["_weakref"] is overriden by the test with a new module, and the new module holds a reference somehow to the previous _weakref module. The old and the new modules remain alive.
History
Date User Action Args
2020-03-24 13:26:06vstinnersetrecipients: + vstinner, shihai1991
2020-03-24 13:26:06vstinnersetmessageid: <1585056366.95.0.223309018439.issue40050@roundup.psfhosted.org>
2020-03-24 13:26:06vstinnerlinkissue40050 messages
2020-03-24 13:26:06vstinnercreate