# Possible garbage collection interaction with Juno

**URL:** <https://discourse.julialang.org/t/possible-garbage-collection-interaction-with-juno/38780>\
**Category:** Juno\
**Created:** [May 5, 2020, 3:08am UTC](https://discourse.julialang.org/t/possible-garbage-collection-interaction-with-juno/38780 "2020-05-05T03:08:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [May 5, 2020, 3:08am UTC](https://discourse.julialang.org/t/possible-garbage-collection-interaction-with-juno/38780/1 "2020-05-05T03:08:08Z")

</div>

Hi,

I’m trying to figure out what’s happening here. Running the following example:

```julia
using DifferentialEquations, Plots

function usode!(du,u,p,t)
    C1 = 1.63e-9
    RS = 791.0
    C2 = 3.3e-9
    C0 = 0.3e-9
    L1 = 1e-3
    L2 = 82e-3
    CM = 4e-12
    LM = 8.0
    RM = 7500.0
    VC1, VC2, VC0, VCM, IL1, IL2, ILM, Vp = u
    fv, VAmag = p
    VA = VAmag*sinpi(2*Vp)
    du[1] = 1/C1*IL1
    du[2] = -1/C2*IL1
    du[3] = 1/C0*(IL1-IL2-ILM)
    du[4] = 1/CM*ILM
    du[5] = 1/L1*(VA-VC1-VC0-VC2-IL1*RS)
    du[6] = 1/L2*VC0
    du[7] = 1/LM*(VC0-VCM-ILM*RM)
    du[8] = fv
end

mutable struct Controller
    f::Float64
end
function(c::Controller)(integrator)
    integrator.p[1] = c.f
    if c.f < 30000.0
        c.f += 15.0
    end
    #println(integrator.t)
end

function sim()
    p = [0.0, 100.0]
    cb1 = PeriodicCallback(Controller(27000.0),0.005)
    cbs = CallbackSet(cb1,)
    u0 = [0.0,0.0,0.0,0.0, 0.0,0.0,0.0, 0.0]
    tspan = [0.0, 1.1]
    prob = ODEProblem(usode!,u0,tspan,p)
    @time sol = solve(prob,Tsit5(), callback=cbs, reltol=1e-8, abstol=1e-8, maxiters=10_000_000)
    sol
end

sol = sim()
sol=nothing
sol=sim()
sol=nothing
sol=sim()
sol=nothing
sol=sim()

```

The `sim()` call makes an object that nearly consumes my computer’s RAM. On the repeated executions, the memory gets released (garbage collected) and then we build it again.

After completion of the script, if I execute another `sol=nothing` followed by `sol=sim()` (either by doing Ctrl-Enter on the appropriate lines, or by typing the commands in at the REPL), the memory does not get released (and my computer crawls to a halt). I suspect something different happens in the Juno environment that prevents the previous `sol` object from getting collected. Adding a `GC.gc()` does not seem to help here.

Any thoughts as to what’s going on?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 5, 2020, 11:10am UTC](https://discourse.julialang.org/t/possible-garbage-collection-interaction-with-juno/38780/2 "2020-05-05T11:10:52Z")

</div>

I can repro the issue (at least in Juno, I didn’t try outside of it).  
It seems likely that we’re accidentally holding on to a reference for the result bubbles/workspace.

We’ll keep track of the issue at  
[https://github.com/JunoLab/Juno.jl/issues/574](https://github.com/JunoLab/Juno.jl/issues/574)

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [May 5, 2020, 2:41pm UTC](https://discourse.julialang.org/t/possible-garbage-collection-interaction-with-juno/38780/3 "2020-05-05T14:41:04Z")

</div>

Thank you!
