Memory leak when calling certain python packages from Julia via PythonCall
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 冷清
- 領域
- performance
研究方向
先使用列出的 Julia、Python 和 package 版本執行提供的 PythonCall 與 matplotlib MWE,然後將其記憶體行為與 numpy 迴圈進行比較。調查為何關閉並刪除 figure 和 axes 後記憶體仍未釋放;當重複迴圈不再無限增長,且已在 REPL 和命令列腳本中驗證該行為時,即視為完成。
由索引模型根據 Issue 內容生成。
描述
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!
- 主要語言
- Julia
- 星號
- 1.1k
- 分支
- 88
- 平均合併
- 3 天 2 小時
- 30 天內合併 PR
- 6
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
JuliaPy/PythonCall.jl 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 55/100
JuliaPy/PythonCall.jl#828 · 7 則留言 ·
維護者通常 2 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
JuliaPy/PythonCall.jl#809 · 2 則留言 ·
維護者通常 2 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 35/100
JuliaPy/PythonCall.jl#805 · 4 則留言 ·
維護者通常 2 天內回覆
-
enhancement
難度 3/5 1-2 天 新手友好度 68/100
JuliaPy/PythonCall.jl#796 ·
維護者通常 2 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 25/100
JuliaPy/PythonCall.jl#790 ·
維護者通常 2 天內回覆
查看 JuliaPy/PythonCall.jl 的全部 Issue
相似的 Issue
-
found-by-agent
難度 2/5 1-3 小時 新手友好度 68/100
exanauts/SparseDirectSolver.jl#92 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
lu_instance/qr_instance run a full factorization for FixedSizeArrays可能已有人在做 @devmotion 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
JuliaArrays/ArrayInterface.jl#510 ·
-
Segfault on x86_64 with AVX: over-aligned vector store可能已有人在做 @vchuravy 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
EnzymeAD/Enzyme.jl#3775 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆