Skip to content

Memory leak in solving ODE many times #1946

Closed
@MasonProtter

Description

@MasonProtter

The following code has monotically increasing memory usage for me and will just keep on growing until the system runs out of RAM and crashes:

julia> using SparseArrays, LinearAlgebra, OrdinaryDiffEq

julia> function memory_leak(;N=100^2)
           for i  1:100
               H = sprandn(N, N, 0.00125/2)
               H = H + H'
               ψ0 = normalize!(randn(ComplexF64, N))
               tspan=(0, 10)
               ∂ₜ(ψ, (; H,), t) = -im * (H * ψ)
               prob = ODEProblem(∂ₜ, ψ0, tspan, (;H))
               ψ = solve(prob, Tsit5(), reltol=1e-8,abstol=1e-8)
           end
       end

julia> memory_leak()

This seems to happen whether or not H is passed as a parameter or is a captured variable in ∂ₜ.


Here's my system:

julia> versioninfo()
Julia Version 1.9.0
Commit 8e63055292* (2023-05-07 11:25 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 12 × AMD Ryzen 5 5600X 6-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver3)
  Threads: 6 on 12 virtual cores
Environment:
  JULIA_NUM_THREADS = 6

(@v1.9) pkg> st OrdinaryDiffEq
Status `~/.julia/environments/v1.9/Project.toml`
  [1dea7af3] OrdinaryDiffEq v6.51.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions