# How to clear variables and/or whole work space

**URL:** <https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149>\
**Category:** New to Julia\
**Created:** [April 4, 2018, 4:42am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149 "2018-04-04T04:42:59Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [January 17, 2023, 9:59pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/27 "2023-01-17T21:59:19Z")

</div>

> [@Nathan\_Boyer](#):
>
> You can set variables equal to `nothing`, but the only way to get a truly clean REPL is to restart it.

That’s right. In any case, even just setting variables to `nothing` might be useful in order to release memory, if there are variables bound to large objects that won’t be used anymore, and you want to keep the Julia session alive (loaded packages, compiled functions, etc.).

This simple function may be used to unbind the objects of all non-constant globals in `Main` (functions, modules, `const` globals, etc. would remain safely untouched):

```julia
function unbindvariables()
    for name in names(Main)
        if !isconst(Main, name)
            Main.eval(:($name = nothing))
        end
    end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149)._
