← 返回首页
bpo-1635741: Fix reference cycle by calling explicit gc collection in main interpreter by shihai1991 · Pull Request #21902 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

bpo-1635741: Fix reference cycle by calling explicit gc collection in main interpreter#21902

Merged
vstinner merged 1 commit into
python:masterfrom
shihai1991:bpo_1635741_gc_collect
Aug 17, 2020
Merged

bpo-1635741: Fix reference cycle by calling explicit gc collection in main interpreter#21902
vstinner merged 1 commit into
python:masterfrom
shihai1991:bpo_1635741_gc_collect

Conversation

shihai1991 commented Aug 17, 2020
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

shihai1991 changed the title WIP: explict gc collection in main interpreter bpo-1635741: explict gc collection in main interpreter Aug 17, 2020

Copy link
Copy Markdown
Member Author

Before this PR:
sys.gettotalrefcount: 14288
sys.gettotalrefcount: 18042
sys.gettotalrefcount: 21796
sys.gettotalrefcount: 25550
sys.gettotalrefcount: 29304
sys.gettotalrefcount: 33058
sys.gettotalrefcount: 36812
sys.gettotalrefcount: 40566
sys.gettotalrefcount: 44320
sys.gettotalrefcount: 48074

After this PR:
sys.gettotalrefcount: 10537
sys.gettotalrefcount: 10540
sys.gettotalrefcount: 10543
sys.gettotalrefcount: 10546
sys.gettotalrefcount: 10549
sys.gettotalrefcount: 10552
sys.gettotalrefcount: 10555
sys.gettotalrefcount: 10558
sys.gettotalrefcount: 10561
sys.gettotalrefcount: 10564

shihai1991 changed the title bpo-1635741: explict gc collection in main interpreter bpo-1635741: Fix reference cycle by calling explicit gc collection in main interpreter Aug 17, 2020
vstinner merged commit 8aa163e into python:master Aug 17, 2020

Copy link
Copy Markdown
Member

Merged since it seems to fix multiple issues: #21902 (comment)

Does it fix your issue with encoding names and encodings._aliases?

Copy link
Copy Markdown
Member

cc @ncoghlan @ericsnowcurrently: Python finalization is getting better ;-) Yet another GC collection at exit!

Copy link
Copy Markdown
Member Author

Merged since it seems to fix multiple issues: #21902 (comment)

Does it fix your issue with encoding names and encodings._aliases?

Yes, this PR have fix my issue. there have no remaining encodings.aliases in refdumps.
Thanks a million, victor. I have learned much in this issue.

Copy link
Copy Markdown
Member

I'm not sure that the GC is still fully functionnal after PyInterpreterState is cleared, but at least, it seems like there were a bunch of reference cycles.

cc @pablogsal

shihai1991 added a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
…honGH-21902) Fix a reference cycle by triggering an explicit GC collection after calling PyInterpreterState_Clear().

ghost commented Aug 26, 2020

Copy link
Copy Markdown

Just curious, what are the three leaks.

Copy link
Copy Markdown
Member Author

Just curious, what are the three leaks.

You found this detail. I checked that some str object own the changed refcount in each iteration(not check the details).

xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
…honGH-21902) Fix a reference cycle by triggering an explicit GC collection after calling PyInterpreterState_Clear().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Footer

© 2026 GitHub, Inc.