# 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:** 7
**Page:** 2

<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, 12:38pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/21 "2022-01-21T12:38:12Z")

</div>

As I have answered on [SO](https://stackoverflow.com/questions/70800177/delete-full-workspace-or-one-variable-in-julia) the currently recommended way is to do all your work inside a custom defined module (i.e. do not define variables in `Main` module but in some submodule). Then you can reload such a custom module. Unfortunately it is not super convenient, but works.

Here is the link [Workflow Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/workflow-tips/#A-basic-editor/REPL-workflow) I to the Julia Manual that describes this workflow.

---

<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, 2:18pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/22 "2022-01-21T14:18:45Z")

</div>

thank you

---

<div class="post-metadata">

### Author: ![tapyu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tapyu/32/37182_2.png) [@tapyu](https://discourse.julialang.org/u/tapyu)
#### Post date: [July 23, 2022, 11:11am UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/23 "2022-07-23T11:11:38Z")

</div>

Based on [Julia’s documentatio](https://docs.julialang.org/en/v1/manual/faq/#How-do-I-delete-an-object-in-memory?-1): “Julia does not have an analog of MATLAB’s clear function”, which clears all variables in the workspace. However, in VsCode, it has a convenient bind to `Alt+J Alt+R` that restart the REPL, cleaning out all variables in the workspace.

---

<div class="post-metadata">

### Author: ![Bienvenue\_Feugang\_Nt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bienvenue_feugang_nt/32/45386_2.png) [@Bienvenue\_Feugang\_Nt](https://discourse.julialang.org/u/Bienvenue_Feugang_Nt)
#### Post date: [January 16, 2023, 10:07pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/24 "2023-01-16T22:07:50Z")

</div>

Hi Guys, Ctrl-L clears the latest part of the console. but none of the above (clearconsole(), CTRL-L, workspace()) works to give me a clean console to work with. I am using VSCode to code in Julia. anyone know what cleans up the console please?

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [January 17, 2023, 4:13pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/25 "2023-01-17T16:13:17Z")

</div>

# Clearing the Console

Ctrl+L should clear all the text from the terminal. You might need to set the keyboard shortcut in VSCode by searching in the command palette then clicking on the settings cog.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a058ebdcc795e3e119b1d8c88f50a995d3e38d7f.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/9/c958a33d38bf2141b60bfcfc61a1787c528dd44e.png)

This is a VSCode command though, not a Julia command. Some of convenience functions that were implemented in the Atom Julia extension like `clearconsole` and `workspace` have not been implemented in the VSCode extension yet. I opened [an issue about adding them](https://github.com/julia-vscode/julia-vscode/issues/1369) a while back.

# Clearing the Workspace

Clearing all variables is not currently possible in Julia. See the documentation about it [here](https://docs.julialang.org/en/v1/manual/faq/#How-do-I-delete-an-object-in-memory?). You can set variables equal to `nothing`, but the only way to get a truly clean REPL is to restart it.

- In VSCode, you can restart with the Restart REPL command (Alt+J, Alt+R by default).  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/3/232ef3313349419e9384b84215e5916d289345fb.png)

- In a standalone terminal window, you can type `exit()` in the REPL then `julia` in the terminal shell.

---

<div class="post-metadata">

### Author: ![Bienvenue\_Feugang\_Nt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bienvenue_feugang_nt/32/45386_2.png) [@Bienvenue\_Feugang\_Nt](https://discourse.julialang.org/u/Bienvenue_Feugang_Nt)
#### Post date: [January 17, 2023, 8:59pm UTC](https://discourse.julialang.org/t/how-to-clear-variables-and-or-whole-work-space/10149/26 "2023-01-17T20:59:25Z")

</div>

Thank you it worked

---

<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

```

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