# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jelly](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Jelly](https://discourse.julialang.org/u/Jelly)\
**Post date:** [April 4, 2018, 4:42am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/1 "2018-04-04T04:42:59Z")

</div>

hello ,i’m a newcomer. i use Atom as my IDE for julia . How to clear the information in REPL and the variables that i do not need in the work space

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [April 4, 2018, 7:08am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/2 "2018-04-04T07:08:05Z")

</div>

I don’t use Atom but in Julia 0.6 REPL, you can use the `workspace()` function to clear things up.

```julia
julia> a = 1
1

julia> a
1

julia> workspace()

julia> a
ERROR: UndefVarError: a not defined

```

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [April 4, 2018, 7:33am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/3 "2018-04-04T07:33:28Z")

</div>

Note that `workspace` is gone in 0.7, so going forward the only way to clear your workspace is to quit and restart Julia.

---

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [April 4, 2018, 10:59pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/4 "2018-04-04T22:59:42Z")

</div>

I think you can replace your variables with nothing and then garbage collect.

The following shows what I mean:

```julia
testbig=rand(10_000,10_000)
testbig=nothing;
gc()

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [April 4, 2018, 11:44pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/5 "2018-04-04T23:44:19Z")

</div>

But then the binding still exists.

---

<div class="post-metadata">

**Author:** ![Juser](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Juser](https://discourse.julialang.org/u/Juser)\
**Post date:** [April 4, 2018, 11:53pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/6 "2018-04-04T23:53:56Z")

</div>

Is that harmful?

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [April 4, 2018, 11:55pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/7 "2018-04-04T23:55:37Z")

</div>

Depends on what you want, just saying it’s different from the behavior of `workspace()`.

---

<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:** [April 5, 2018, 11:25am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/8 "2018-04-05T11:25:16Z")

</div>

Using `workspace()` in Juno is a bad idea and will break all sorts of things, so I’d _really_ advise against it.

You can clear the REPL display with `Ctrl-J Ctrl-C` or by typing `clearconsole()` into the REPL, however.

---

<div class="post-metadata">

**Author:** ![Jelly](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Jelly](https://discourse.julialang.org/u/Jelly)\
**Post date:** [April 5, 2018, 11:58am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/9 "2018-04-05T11:58:00Z")

</div>

thank u all very much . i got it.

---

<div class="post-metadata">

**Author:** ![oviedorodolfo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oviedorodolfo/32/5314_2.png) [@oviedorodolfo](https://discourse.julialang.org/u/oviedorodolfo)\
**Post date:** [December 5, 2018, 1:11pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/10 "2018-12-05T13:11:39Z")

</div>

Ctrl+J, Ctrl+C will clear the Console but not the Workspace: the variables and functions created are not cleared.

You can clear the Workspace from the Console by pressing Ctrl+D to end Julia and Enter to start it again. This works reasonably fast.

I am working in Juno/JuliaPro. Is there any other method to clear the Workspace without stopping Julia?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 5, 2018, 1:33pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/11 "2018-12-05T13:33:24Z")

</div>

> [@oviedorodolfo](#):
>
> Is there any other method to clear the Workspace without stopping Julia?

There used to be a `workspace()` function, but it was removed as it had some problems. I think that the consensus is that stopping and restarting the process is now fast enough for practical purposes.

---

<div class="post-metadata">

**Author:** ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://discourse.julialang.org/u/simon)\
**Post date:** [February 1, 2019, 4:42pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/12 "2019-02-01T16:42:54Z")

</div>

It is fast when the project doesn’t have many dependencies. But with more dependencies, it takes more time. Is there any method to restart without precompile again?

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [July 4, 2020, 10:42am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/13 "2020-07-04T10:42:27Z")

</div>

> [@oviedorodolfo](#):
>
> Ctrl+J, Ctrl+C will clear the Console but not the Workspace

It does not work with Julia 1.4.2 on Windows 10. According to the documentation [Key bindings](https://docs.julialang.org/en/v1/stdlib/REPL/#Key-bindings-1), it should be **Ctrl + L** now.

I do not find how to clear variables in that documentation. The workaround is just to restart Julia.

---

<div class="post-metadata">

**Author:** ![Soumya\_Boral](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soumya_boral/32/19741_2.png) [@Soumya\_Boral](https://discourse.julialang.org/u/Soumya_Boral)\
**Post date:** [November 26, 2020, 6:37pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/14 "2020-11-26T18:37:36Z")

</div>

There should be a way to clear workspace. Ctrl+L clears the console but the objects are still there. Restarting is a bad way of doing things.

---

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [April 22, 2021, 11:42am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/15 "2021-04-22T11:42:45Z")

</div>

How about names(Main), then nothing-ing everyting in the list that you want to clear?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 22, 2021, 1:31pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/16 "2021-04-22T13:31:16Z")

</div>

This will not work for any `const`s, also, attributing `nothing` to a binding is different from it never existing (for example, as you pointed out, it will appear in the output of `names`).

---

<div class="post-metadata">

**Author:** ![joseph\_s](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joseph_s/32/21267_2.png) [@joseph\_s](https://discourse.julialang.org/u/joseph_s)\
**Post date:** [November 16, 2021, 8:03am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/17 "2021-11-16T08:03:06Z")

</div>

Ctrl+L to clear the REPL

---

<div class="post-metadata">

**Author:** ![ga72kud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ga72kud/32/32180_2.png) [@ga72kud](https://discourse.julialang.org/u/ga72kud)\
**Post date:** [January 21, 2022, 11:05am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/18 "2022-01-21T11:05:55Z")

</div>

I have searched for a while and experimenting with CommonRLInterface [https://github.com/JuliaReinforcementLearning/CommonRLInterface.jl](https://github.com/JuliaReinforcementLearning/CommonRLInterface.jl). There are some mutable variables. I am not an expert in Julia Programming, but I want to clear the whole workspace or delete a mutable variable (which is not allowed for mutable variables as far as I understand it, but in CommonRLInterface it comes from AbstractEnv superclass so I cannot change it).

```
struct myEnv <: AbstractEnv 

julia> myGridWorld=Nothing
ERROR: invalid redefinition of constant myGridWorld
Stacktrace:
 [1] top-level scope
   @ none:1

```

I want to clear the whole workspace. So I have to stop julia and restart it again. In addition I have to activate the environment again.

It would help me if there would exist a button or keyshortcut, which automatically resets the workspace, starting a new julia kernel if necessary and activates the last environment (maybe also restarting the code).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [January 21, 2022, 11:36am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/19 "2022-01-21T11:36:18Z")

</div>

see [Clear workspace à la Pluto](https://discourse.julialang.org/t/clear-workspace-a-la-pluto/74484)

---

<div class="post-metadata">

**Author:** ![ga72kud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ga72kud/32/32180_2.png) [@ga72kud](https://discourse.julialang.org/u/ga72kud)\
**Post date:** [January 21, 2022, 12:25pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/20 "2022-01-21T12:25:20Z")

</div>

Thank you @bkamins. As far as I understand there is not a direct solution available, but by using using REPLinModule, one could set a mode for the REPL

using REPLinModule

I am not sure if I understand the post right …

[Next page](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149.md?page=2)
