Skip to content

Leak with untracked tuples and deferred ref counts #144054

Description

@nascheme

Bug report

Bug description:

With the merge of gh-142843, the test case test__interpchannels.ChannelTests.test_send_recv_different_interpreters_and_threads is now failing with reference leaks. A minimal reproducer is below. If the sys.flags object has deferred reference counting enabled in the sub-interpreter, it leaks.

importgcimportsysimport_interpretersdeftest_leak():
id1=_interpreters.create()
deff():
# enable deferred ref counts for sys.flags, causes a leak, even with# an explicit gc.collect() call_interpreters.run_string(
id1,
'import sys, _testcapi; _testcapi.pyobject_enable_deferred_refcount(sys.flags)\n',
)
f()
_interpreters.destroy(id1)
defmain():
foriinrange(4):
test_leak()
gc.collect()
old_refs=sys.gettotalrefcount()
foriinrange(10):
test_leak()
gc.collect()
refs=sys.gettotalrefcount()
print(f'refs {refs} diff {refs-old_refs}')
old_refs=refsif__name__=='__main__':
main()

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions