plotly / plotly/plotly.py

memory leak in Python 3.13 free-threaded build

Open
#5,176 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 regression
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

I spent some time trying to debug a memory leak caused by calling plotly.express.line within a Dash live update callback under a Python 3.13.3t (free-threaded). Setting PYTHON_GIL=0 or PYTHON_GIL=1 appears to make no difference.

By no means have I located the root cause of the issue (not yet anyway), but I've been able to at least narrow it down to at least one problematic line of code in the BaseFigure class

https://github.com/plotly/plotly.py/blob/main/plotly/basedatatypes.py#L581

If I run the example code shown below (which is HIGHLY distilled from the originating Dash app I was trying to debug), the memory footprint seems to steadily climb with each iteration. If I comment out the offending line within BaseFigure (shown above), the memory footprint remains stable

#!/usr/bin/env -S python3 -u

import sys
import time
from plotly.basedatatypes import BaseFigure

gil = sys._is_gil_enabled()
print(f'GIL enabled = {gil}')

while True:
    BaseFigure()
    BaseFigure()
    BaseFigure()
    time.sleep(.01)

For long running applications like the one described earlier, slow and steady memory consumption issues are causing some rather significant issues.

System details

OS: docker://python:3.12-slim-bookworm
Arch: aarch64
Python version: uv python install 3.13.3t
Plotly version: 6.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the distilled BaseFigure loop under Python 3.13.3t and observing its memory footprint. Inspect plotly/basedatatypes.py around line 581, then compare behavior with that line commented out. Done means identifying the cause and confirming that repeated BaseFigure creation no longer causes steady memory growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.