# Memory leak in Browser when using WebIO + Interact (+ VegaLite)?

**URL:** <https://discourse.julialang.org/t/memory-leak-in-browser-when-using-webio-interact-vegalite/21332>\
**Category:** General Usage\
**Tags:** web, bug\
**Created:** [March 1, 2019, 7:05am UTC](https://discourse.julialang.org/t/memory-leak-in-browser-when-using-webio-interact-vegalite/21332 "2019-03-01T07:05:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnliao](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Post date:** [March 1, 2019, 7:05am UTC](https://discourse.julialang.org/t/memory-leak-in-browser-when-using-webio-interact-vegalite/21332/1 "2019-03-01T07:05:15Z")

</div>

My browser tab consumes unlimited amount of memory after I evaluated the following snippet in a Jupyter notebook and dragged the slider back and forth quickly for a dozen of times.

Throttling the `slider` observable alleviates but does not cure the memory issue. So I guess that some Javascript object sent to the browser is somehow not freed.

Another issue is that I have to refresh the notebook webpage once before the slider works.

Some maybe relevant info:  
Julia: v1.1.0  
browser: Google Chrome Version 72.0.3626.119 (Official Build) (64-bit)  
OS: Archlinux  
WebIO: #master  
Interact: 0.9.1  
IJulia: 1.17.0

Any suggestions appreciated!

```julia
using DataFrames
using Interact
using JSExpr
using WebIO
using VegaLite: @vlplot
ASSETS = [
    "vega-lib"=>"https://cdn.jsdelivr.net/npm/vega@4.4.0/build/vega.min.js",
    "vega-lite"=>"https://cdn.jsdelivr.net/npm/vega-lite@3.0.0-rc12/build/vega-lite.min.js",
    "https://cdn.jsdelivr.net/npm/vega-embed@3.29.1/build/vega-embed.min.js",
];
n = 10_000

f(v) = DataFrame(x=1:n, y=sin.((1:n)./v)) |> @vlplot(:line, x="x", y="y") |> spc->spc.params

w = Scope(;imports=ASSETS)
onimport(w, @js function (vg,vl,ve)
# can this be the culprit? But otherwise I don't know how to access the imported modules.
    self.ve = function (spc)
        ve("#ddd", spc)
    end
end)
obs = Observable(w, "spc", f(1))

s = slider(1:n)
on(s) do v
    obs[] = f(v)
end

onjs(obs, @js val -> begin
    self.ve(val)
end)

s |> display
w(node(:div, "aaaa"; id="ddd")) |> display

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [March 1, 2019, 9:46pm UTC](https://discourse.julialang.org/t/memory-leak-in-browser-when-using-webio-interact-vegalite/21332/2 "2019-03-01T21:46:40Z")

</div>

I’m not really familiar with WebIO and Interact, so other than saying that we didn’t take support for that into account in how we designed VegaLite.jl, I don’t have any further insights into that particular combo.

Having said that, maybe another tactic would be to use Vega-Lite interactions directly to achieve a similar outcome? They are documented at [Selection Parameters | Vega-Lite](https://vega.github.io/vega-lite/docs/selection.html). That would only work in either JupyterLab or nteract, not in the classic notebook, though.

---

<div class="post-metadata">

**Author:** ![cnliao](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Post date:** [March 1, 2019, 10:17pm UTC](https://discourse.julialang.org/t/memory-leak-in-browser-when-using-webio-interact-vegalite/21332/3 "2019-03-01T22:17:27Z")

</div>

For my application client side filtering and transformation is not feasible and needs to be done in Julia on a cluster. Moreover a few weeks ago I tried Jupiter lab but interactivity was lacking due to possible version issues with the vega/vegalite they ship. Using webio is also a bit faster because ijulia render svg and png version of a vegalite specification regardless of whether a richer/better mime type is showable.

That said I really like the mini DSL in VegaLite.jl. I find it much easier to write than vanilla json specifications. Thank you for making it!
