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

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

Merged
merged 1 commit into from
Aug 17, 2020

Conversation

shihai1991
Copy link
Member

@shihai1991 shihai1991 commented Aug 17, 2020

@shihai1991 shihai1991 changed the title WIP: explict gc collection in main interpreter bpo-1635741: explict gc collection in main interpreter Aug 17, 2020
@shihai1991
Copy link
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 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 vstinner merged commit 8aa163e into python:master Aug 17, 2020
@vstinner
Copy link
Member

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

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

@vstinner
Copy link
Member

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

@shihai1991
Copy link
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.

@vstinner
Copy link
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
Copy link

ghost commented Aug 26, 2020

Just curious, what are the three leaks.

@shihai1991
Copy link
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().
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