Memory leak with pyplot
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne mit dem bereitgestellten Julia MWE und den PyCall-Aufrufen zu pyplot und vergleiche die Speichernutzung mit und ohne Erstellung von Plots und Garbage Collection. Verfolge die zurückgegebenen fig- und plot-Objekte durch PyCall; abgeschlossen ist die Aufgabe, wenn die beibehaltenen Referenzen identifiziert und behoben sind, sodass wiederholtes Plotten nicht mehr zu unbegrenztem Speicherwachstum führt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Julia
- Sterne
- 1.5k
- Forks
- 186
- Ø Merge
- 7 T. 10 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JuliaPy/PyCall.jl
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
Alle Issues in JuliaPy/PyCall.jl
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Add project: Typst_jll.jlEvtl. vergeben @github-actions hat das heute übernommen. Offenadd-project
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 76/100
YDX-2147483647/best-of-typst#590 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100