Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Memory leak when calling certain python packages from Julia via PythonCall

Aberta
#759 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
julia, matplotlib, python
Domínio
performance

Direção de pesquisa

Comece executando o MWE fornecido de PythonCall e matplotlib com as versões listadas de Julia, Python e dos pacotes e, em seguida, compare seu comportamento de memória com o loop de numpy. Investigue por que fechar e excluir a figura e os eixos não libera memória; considera-se concluído quando o loop repetido não crescer mais indefinidamente e o comportamento for verificado na REPL e no script de linha de comando.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

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!

Linguagem predominante
Julia
Estrelas
1.1k
Forks
89
Merge médio
2d 15h
PRs com merge (30d)
7

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de JuliaPy/PythonCall.jl

Todas as issues de JuliaPy/PythonCall.jl

Issues semelhantes

Mais issues de Julia

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.