Memory leak with pyplot
还没有人认领这个 Issue。
评估
调研方向
从提供的 Julia MWE 和对 pyplot 的 PyCall 调用开始,比较创建绘图和进行垃圾回收与不创建绘图和不进行垃圾回收时的内存使用情况。通过 PyCall 跟踪返回的 fig 和 plot 对象;完成的标准是识别并修复被保留的引用,使重复绘图不再导致内存无限增长。
由索引模型根据 Issue 内容生成。
描述
When I create matplotlib.pyplot plots, the memory keeps increasing and is not released by the garbage collector. The following is the case I'm interested in (with subplots) and bellow I include a more basic MWE.
Example with subplots
using PyCall
plt = pyimport("matplotlib.pyplot")
function test_pyplot()
for i in 1:10000
@info i
z = rand(4, 50)
ẑ = rand(4, 50)
fig, axs = plot_pyplot(z, ẑ)
end
end
function plot_pyplot(z, ẑ)
# plt = pyimport("matplotlib.pyplot")
N = Int(size(z, 1)/2)
fig, axs = plt.subplots(2, N)
for i in 1:N
axs[1,i].plot(z[i,:], label = "true")
axs[1,i].plot(ẑ[i,:], label = "model")
axs[2,i].plot(z[i+N,:], label = "true")
axs[2,i].plot(ẑ[i+N,:], label = "predicted")
axs[2,i].set_xlabel("time steps")
axs[i].grid(true)
axs[i+N].grid(true)
axs[i+N].label_outer()
axs[i].label_outer()
end
# plt.close()
return fig, axs
end
test_pyplot()
I tried defining plt and closing it inside the plot_pyplot function (commented lines) but it doesn't solve the memory leak.
Here you have a simpler MWE:
using PyCall
plt = pyimport("matplotlib.pyplot")
plot_pyplot(z) = plt.plot(z)
function test_pyplot()
for i in 1:1000000
@info i
z = rand(50)
fig = plot_pyplot(z)
end
end
Version info and status
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.3.0)
CPU: 8 × Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
Threads: 1 on 6 virtual cores
(memory_leak) pkg> st
Status `~/Documents/issues/memory_leak/Project.toml`
[438e738f] PyCall v1.94.1
I need to use pyplot directly from PyCall.jl and not through PyPlot.jl because I need to pass the fig object to Wandb.jl. Actually, maybe I could get that object from PyPlot.jl, I didn't try that yet. But since I found the bug here, I think it can be helpful to report it anyway.
- 主要语言
- Julia
- 星标
- 1.5k
- 派生
- 186
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaPy/PyCall.jl 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
Meta-Issue: Mutli-threading leads to segfaults可能已有人在做 @topolarity 于 211 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 20/100
-
Crashes with Julia 1.12 and Revise.jl可能已有人在做 @topolarity 于 211 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 45/100
查看 JuliaPy/PyCall.jl 的全部 Issue
相似的 Issue
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up steps可能已有人在做 @thevolatilebit 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
难度 2/5 1-3 小时 新手友好度 68/100
exanauts/SparseDirectSolver.jl#92 ·
维护者通常 1 天内回复
-
`inv` of a dense matrix fails for arrays whose `parent` is not an array of the same kind可能已有人在做 @devmotion 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
JuliaLang/LinearAlgebra.jl#1740 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
NumericalEarth/Breeze.jl#1051 ·
维护者通常 1 天内回复