Skip to content

Runaway memory use when repeatedly printing empty string #151814

Description

@pastries-yay

Bug report

Bug description:

Printing the empty string in a loop seems to cause memory use of Python to grow without bound.

whileTrue:
print('', end='')

or

importsyswhileTrue:
sys.stdout.write('')

The latter apparently does not work in interactive mode.

Relatedly,

whileTrue:
for_inrange(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

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions