Skip to content

gh-111330: Fix GC of _pyio.BytesIO with exports - #152335

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
cmaloney:pyio_bytesio_close
Aug 8, 2026
Merged

gh-111330: Fix GC of _pyio.BytesIO with exports#152335
serhiy-storchaka merged 2 commits into
python:mainfrom
cmaloney:pyio_bytesio_close

Conversation

@cmaloney

@cmaloneycmaloney commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Swap out the buffer rather than using .clear() which will raise an exception if there are exports. Rely on bytearray (self._buffer) being the exported object to make sure it doesn't get garbage collected.

Swap out the buffer rather than using `.clear()` which will raise an
exception if there are epxorts.

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka merged commit 998b890 into python:mainAug 8, 2026
55 checks passed
@cmaloney
cmaloney deleted the pyio_bytesio_close branch August 8, 2026 15:59
@cmaloney

Copy link
Copy Markdown
ContributorAuthor

Thanks for the review @serhiy-storchaka !

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@cmaloney@serhiy-storchaka