JuliaPy / JuliaPy/PythonCall.jl

Memory leak when calling certain python packages from Julia via PythonCall

オープン
#759 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Julia
スター
1.1k
フォーク
86
平均マージ
1日 22時間
マージ済み PR(30日)
3

説明

Affects: PythonCall

Describe the bug

Memory is not released when repeatedly creating and closing matplotlib figures via PythonCall. I originally had the issue with an elaborate cartopy plotting loop, but have managed to recreate it in a simple while true loop MWE. Each iteration allocates a new figure/axes via plt.subplots, immediately closes it with plt.close, calls PythonCall.pydel! on both the figure and axes objects, and calls GC.gc(). However, there is still a leak until the process is killed.

This does not occur when repeatedly allocating and deleting a numpy array in an equivalent loop, so the issue has something to do with what kind of python objects are created. I also have similar memory leak issues with scikit-learn.

The issue is reproducable both in the Julia REPL and in the VS Code Julia extension, and when I execute a script containing the below code from the command line.

MWE:
using PythonCall
@py import matplotlib.pyplot as plt

i = 0
while true
global i += 1
fig, ax = plt.subplots(1, 1)
plt.close(fig)
PythonCall.pydel!(ax)
PythonCall.pydel!(fig)
GC.gc()
println("Iteration $i done")
end

My system

OS: macOS 15.7.4 (arm64, Apple Silicon)
Julia: 1.12.6
Python: 3.14.2 (conda-forge, Clang 20.1.8)
PythonCall: 0.9.31
matplotlib: 3.10.8

Thanks for your help!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start by running the supplied PythonCall and matplotlib MWE with the listed Julia, Python, and package versions, then compare its memory behavior with the numpy loop. Investigate why closing and deleting the figure and axes does not release memory; done means the repeated loop no longer grows indefinitely and the behavior is verified in the REPL and command-line script.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
julia, matplotlib, python
領域
performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。