Skip to content

BUG: memory leak in to_json when converting DateTime values #62204

@swt2c

Description

@swt2c

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 main branch of pandas.

Reproducible Example

import pandas as pd
while True:
    dr = pd.date_range(start='1/1/2019', end='1/2/2019', freq='s', tz='UTC')
    df = pd.DataFrame({'col1': [12.34]}, index=dr)
    df.reset_index().to_json(orient='values', date_format='iso')

Issue Description

There appears to be a memory leak in Pandas to_json() when converting DateTime values. When running the reproducer, the system's memory use will continuously increase.

Expected Behavior

Memory use should be stable.

Installed Versions

__ INSTALLED VERSIONS ------------------ commit : 4665c10 python : 3.11.13 python-bits : 64 OS : Linux OS-release : 6.14.0-1012-aws Version : #12~24.04.1-Ubuntu SMP Fri Aug 15 00:16:05 UTC 2025 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.3.2
numpy : 2.3.2
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : 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