# Clearing workspace

**URL:** <https://discourse.julialang.org/t/clearing-workspace/29465>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 3, 2019, 8:19pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465 "2019-10-03T20:19:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [October 3, 2019, 8:19pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465/1 "2019-10-03T20:19:16Z")

</div>

Im currently on v1.1.1 using iJulia/Jupyter - i cant find a working method for garbage collection - workspace() and gc() aren’t recognized in REPL or iJulia. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [October 3, 2019, 8:30pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465/2 "2019-10-03T20:30:43Z")

</div>

Button restart kernel?

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [October 3, 2019, 8:52pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465/3 "2019-10-03T20:52:34Z")

</div>

i want to delete tmp vars inside functions to free up memory

---

<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:** [October 3, 2019, 9:00pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465/4 "2019-10-03T21:00:15Z")

</div>

Can you give an example of what you mean? Any variables allocated within a function which are not returned or stored somewhere will automatically be cleaned up without you needing to do anything.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [October 4, 2019, 2:30am UTC](https://discourse.julialang.org/t/clearing-workspace/29465/5 "2019-10-04T02:30:17Z")

</div>

> [@rdeits](#):
>
> Any variables allocated within a function which are not returned or stored somewhere will automatically be cleaned up without you needing to do anything.

This doesn’t happen immediately though. I had a DataFrame taking up 22Gb of my 32Gb system. I reassigned the variable to an empty DataFrame, but the memory was still occupied. I had to kill the Julia process in order to run some other memory-intensive (non-julia) programs.

Sure, if the Julia process needs more memory, it can be freed up, but it would be nice to be able to trigger gc manually.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [October 4, 2019, 7:45am UTC](https://discourse.julialang.org/t/clearing-workspace/29465/6 "2019-10-04T07:45:48Z")

</div>

`GC.gc()` should do the trick most of the time… Otherwise, the OS will take care of it by using the cached pages or swapping aggresively whatever is not needed. Having a large swapfile on very fast storage i.e. NVME raid (2-4GB/s) can help a lot for memory-intensive tasks but it still is an expensive option.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [October 4, 2019, 12:46pm UTC](https://discourse.julialang.org/t/clearing-workspace/29465/7 "2019-10-04T12:46:47Z")

</div>

> [@zgornel](#):
>
> `GC.gc()` should do the trick most of the time…

Ahh, yes. That’s what I needed… I think it used to be exported (so you didn’t need the `GC.` part) - a bunch of things I found with searching mentioned that, but I figured it had been removed.

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [October 5, 2019, 2:04am UTC](https://discourse.julialang.org/t/clearing-workspace/29465/8 "2019-10-05T02:04:53Z")

</div>

this is what i was looking for - thanks
