Bug report
Bug description:
Printing the empty string in a loop seems to cause memory use of Python to grow without bound.
while True: print('', end='')
or
import sys while True: sys.stdout.write('')
The latter apparently does not work in interactive mode.
Relatedly,
while True: for _ in range(10**8): print('', end='') print()
causes memory use to grow to about 1.5GB and then reset when the newline is printed.
CPython versions tested on:
3.14, 3.11, 3.13
Operating systems tested on:
Linux
Linked PRs
- gh-151814: Fix unbounded memory growth from repeated empty writes to
io.TextIOWrapper#151817 - [3.15] gh-151814: Fix unbounded memory growth from repeated empty writes to
io.TextIOWrapper(GH-151817) #152071 - [3.14] gh-151814: Fix unbounded memory growth from repeated empty writes to
io.TextIOWrapper(GH-151817) #152072 - [3.13] gh-151814: Fix unbounded memory growth from repeated empty writes to
io.TextIOWrapper(GH-151817) #152073 - gh-151814: Add test for TextIOWrapper.write unbounded memory growth from repeated writes #152244