JuliaGizmos / Interact.jl

Interactive widgets to play with your Julia code
Other
520 stars 75 forks source link

Memory leak #351

Open cstjean opened 4 years ago

cstjean commented 4 years ago

On Interact v0.10.3, Julia 1.3.1, the following code leaks memory:

julia> using Interact

julia> function gui()
           f = rand(100_000_000)
           dropd = Widgets.dropdown(["a", "b"])
           on(dropd) do _
               println(maximum(f))
           end
           dropd
       end
gui (generic function with 2 methods)

julia> nothing; gui(); 1
1

julia> nothing; gui(); 1
1

...

Memory usage goes up after each call, even after GC.gc().

cstjean commented 4 years ago
julia> function mk_obs()
           f = rand(100_000_000)
           obs = Observable(0)
           on(obs) do _
               println(maximum(f))
           end
           obs
       end
mk_obs (generic function with 1 method)

does not leak memory, so it's something about the widgets. Is anything holding a reference to it? With the dropdown,

julia> WebIO.observ_id_dict
WeakKeyDict{Any,Any} with 2 entries:
  Observable{Any} with 2 l… => (WeakRef(Scope(Node{DOM}(DOM(:html, :div), Any[N…
  Observable{Any} with 1 l… => (WeakRef(Scope(Node{DOM}(DOM(:html, :div), Any[N…

after GC.

cstjean commented 4 years ago

I'm guessing it's some variant of https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187.

twavv commented 4 years ago

Yeah, this is essentially just https://github.com/JuliaGizmos/WebIO.jl/issues/321.

It's being tackled in https://github.com/JuliaGizmos/WebIO.jl/issues/368, but my day job has picked up and I haven't had the time to work on it recently.