Skip to content

Runaway memory use when repeatedly printing empty string #151814

@pastries-yay

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.

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

Metadata

Metadata

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions