# How to release memory from jupyter notebook?

**URL:** https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886
**Category:** Jupyter-Notebook
**Created:** [March 10, 2021, 2:39pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886 "2021-03-10T14:39:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bharland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bharland/32/22762_2.png) [@bharland](https://discourse.julialang.org/u/bharland)
#### Post date: [March 10, 2021, 2:39pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/1 "2021-03-10T14:39:14Z")

</div>

Here is a minimal example that reproduces my problem on a new JupyterLab kernel:  
`x = rand(2^29); varinfo()`  
shows the 4.00 Gb size of ‘x’. But  
`x = nothing`  
does not release this memory. varinfo shows that it is indeed 0.00 Gb, but it’s showing up with top and my system monitor.

What am I missing here? Thanks!

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [March 10, 2021, 2:41pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/2 "2021-03-10T14:41:12Z")

</div>

You can manually invoke the garbage collector with GC.gc(). It should release the memory.

---

<div class="post-metadata">

### Author: ![bharland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bharland/32/22762_2.png) [@bharland](https://discourse.julialang.org/u/bharland)
#### Post date: [March 10, 2021, 2:42pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/3 "2021-03-10T14:42:25Z")

</div>

You’re right! Thanks so much.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [March 10, 2021, 2:46pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/4 "2021-03-10T14:46:11Z")

</div>

The Jupyter notebook interface also stores a reference to the output value of every cell, so your giant array might still be stored as `Out[n]` where `n` is the cell number in which you computed `x`.

You can do `empty!(Out)` to clear that dictionary manually (I don’t know if this is actually a recommended thing to do, but it seems to work). Or you can restart the Jupyter kernel, but I assume that’s not what you actually want.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [March 10, 2021, 4:15pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/5 "2021-03-10T16:15:55Z")

</div>

Sorry just to be clear, this is only about the output of a cell? I.e. if I have

```julia
df = CSV.read(myhugefile.csv, DataFrame)

data = df[1:10, 1:5]

df = nothing

```

in a cell then there would not be a reference to the full data read in from csv?

EDIT: I should probably just check this myself but unfortunately my computer is currently unusable due to processing some large csv files in a Jupyter notebook 🙂

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [March 10, 2021, 4:28pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/6 "2021-03-10T16:28:04Z")

</div>

Yeah, as far as I know that’s correct. The `Out` dictionary just holds the value of the last expression in the cell (the same way all Julia blocks implicitly return the value of their last expression).

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [March 10, 2021, 5:33pm UTC](https://discourse.julialang.org/t/how-to-release-memory-from-jupyter-notebook/56886/7 "2021-03-10T17:33:21Z")

</div>

> [@rdeits](#):
>
> You can do `empty!(Out)` to clear that dictionary manually (I don’t know if this is actually a recommended thing to do, but it seems to work).

Yes, it is documented: [Using IJulia · IJulia](https://julialang.github.io/IJulia.jl/dev/manual/usage/#Input-and-output-history)
