You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak when calling certain python packages from Julia via PythonCall #759
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
Activity