Skip to content

gh-151814: Add test for TextIOWrapper.write unbounded memory growth from repeated writes#152244

Open
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:gh_151814_test
Open

gh-151814: Add test for TextIOWrapper.write unbounded memory growth from repeated writes#152244
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:gh_151814_test

Conversation

@cmaloney

@cmaloney cmaloney commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Use tracemalloc to measure memory usage.

Fails before GH-151817, passes after. Validated by changing condition between > 0 and >= 0 and rebuilding + running make && ./python -m test test_io.test_textio -m "test_write_empty_no_memory_growth".

if (bytes_len > 0) {

Inspired by the report memory usage helper in GH-152203 (If it gets more use should probably move to test.support).

cc: @StanFromIreland

…owth from repeated writes

Use tracemalloc to measure memory usage.
@StanFromIreland

Copy link
Copy Markdown
Member

Inspired by the report memory usage helper in #152203

You're linking to a PR where they had to fix-up such a test, as such, I'm not convinced this is worth it.

@cmaloney

cmaloney commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

In this case the allocations go on my machine from peak = 3067536 to peak = 0 blocks allocated. I think it's unlikely more allocations will happen in this empty global constant string write case. Even if we do add some new overheads with 200_000 iterations if we allocate 200_000 blocks probably worth making sure the change is intentional. Can up the constant further if worried about other overhead creep as the codebase evolves.

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

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants