Skip to content

Memory leak of 30Gb on Linux platform #58967

@juliohm

Description

@juliohm

MWE:

using NearestNeighbors
using StaticArrays
using Random

x(i) = float.(Tuple(CartesianIndices((100,100,100))[i]))

function mwe()
  Random.seed!(123)

  sources = rand(1:100*100*100, 3000) |> unique

  others = setdiff(1:100*100*100, sources)

  batches = Iterators.partition(others, 10^3)

  kdtree = KDTree([SVector(x(i)...) for i in sources])

  dists = []
  for batch in batches
    xs = [SVector(x(i)...) for i in batch]
    _, ds = knn(kdtree, xs, length(sources), true)
    append!(dists, ds)
  end
end

mwe()

If you run it on Julia >= v1.10 on Linux, it leaks 30Gb of memory. Posterior calls to Base.GC.gc() don't release memory.

[b8a86587] NearestNeighbors v0.4.21
[90137ffa] StaticArrays v1.9.13
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 8 default, 0 interactive, 4 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

Moved from KristofferC/NearestNeighbors.jl#208

Metadata

Metadata

Assignees

No one assigned

    Labels

    GCGarbage collectorbugIndicates an unexpected problem or unintended behaviorsystem:linuxAffects only Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions