Skip to content

BUG: Memory leak with pandas.concat #44982

Closed
@danr

Description

@danr

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
import os
import subprocess

df1 = pd.DataFrame(data={'col': range(10000000)})
df2 = pd.DataFrame(data={'col': range(10000000)})
while True:
    pd.concat([df1, df2], axis=0)
    cmd = f'ps --no-headers -e -o rss -q {os.getpid()}'.split()
    rss = int(subprocess.check_output(cmd))
    print(f'{rss = }')

Issue Description

The resident set size (rss) keeps growing with this example which uses pandas.concat even though memory should be constant.

Expected Behavior

The memory should be constant.

Installed Versions

$ python3.10 -c 'import pandas; pandas.show_versions()'

INSTALLED VERSIONS
------------------
commit           : 66e3805b8cabe977f40c05259cc3fcf7ead5687d
python           : 3.10.0.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.15.6-arch2-1
Version          : #1 SMP PREEMPT Thu, 02 Dec 2021 15:47:09 +0000
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.3.5
numpy            : 1.21.3
pytz             : 2021.3
dateutil         : 2.8.2
pip              : 21.3.1
setuptools       : 57.4.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.0.2
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.4.3
numexpr          : 2.7.3
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.7.3
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions