# Does Julia has the similar command \`clear all\` or \`cls\` in matlab?

**URL:** <https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809>\
**Category:** General Usage\
**Created:** [May 27, 2022, 6:42pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809 "2022-05-27T18:42:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [May 27, 2022, 6:42pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/1 "2022-05-27T18:42:25Z")

</div>

Dear all,

Does Julia has the similar command `clear all` or `cls` in matlab?  
I want to clear all the variable or packages which are used.

---

<div class="post-metadata">

**Author:** ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)\
**Post date:** [May 27, 2022, 6:45pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/2 "2022-05-27T18:45:06Z")

</div>

Copy-pasted from [How do I delete an object in memory?](https://docs.julialang.org/en/v1/manual/faq/#How-do-I-delete-an-object-in-memory?)

### How do I delete an object in memory?

Julia does not have an analog of MATLAB’s `clear` function; once a name is defined in a Julia session (technically, in module `Main` ), it is always present.

If memory usage is your concern, you can always replace objects with ones that consume less memory. For example, if `A` is a gigabyte-sized array that you no longer need, you can free the memory with `A = nothing` . The memory will be released the next time the garbage collector runs; you can force this to happen with [`GC.gc()`](https://docs.julialang.org/en/v1/base/base/#Base.GC.gc). Moreover, an attempt to use `A` will likely result in an error, because most methods are not defined on type `Nothing` .

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 27, 2022, 6:52pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/3 "2022-05-27T18:52:40Z")

</div>

Yes, restart Julia.

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [May 27, 2022, 6:56pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/4 "2022-05-27T18:56:26Z")

</div>

I don’t know how to restart Julia in vscode. I try to type `ctrl + C`, but it does not work.

 ![截屏2022-05-28 02.55.52](https://global.discourse-cdn.com/julialang/original/3X/5/d/5dc3eb4c80c30fe231e97234a1259d90840c4a01.png)

---

<div class="post-metadata">

**Author:** ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)\
**Post date:** [May 27, 2022, 7:06pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/5 "2022-05-27T19:06:16Z")

</div>

Ctrl-D or `exit()`

---

<div class="post-metadata">

**Author:** ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)\
**Post date:** [May 27, 2022, 7:08pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/6 "2022-05-27T19:08:48Z")

</div>

Thanks. I works well.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 28, 2022, 8:50pm UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/7 "2022-05-28T20:50:43Z")

</div>

There is a command “Restart Julia REPL”.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [May 29, 2022, 12:35am UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/8 "2022-05-29T00:35:13Z")

</div>

> [@JohnnyChen94](#):
>
> If memory usage is your concern, you can always replace objects with ones that consume less memory. For example, if `A` is a gigabyte-sized array that you no longer need, you can free the memory with `A = nothing` . The memory will be released the next time the garbage collector runs; you can force this to happen with [`GC.gc()`](https://docs.julialang.org/en/v1/base/base/#Base.GC.gc). Moreover, an attempt to use `A` will likely result in an error, because most methods are not defined on type `Nothing` .

Is this something I should actually be doing in my code? Or can I expect the compiler to figure out that it can deallocate the memory of `A` when it is no longer being used, in which case this is more of a REPL tip?

---

<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:** [May 29, 2022, 1:03am UTC](https://discourse.julialang.org/t/does-julia-has-the-similar-command-clear-all-or-cls-in-matlab/81809/9 "2022-05-29T01:03:08Z")

</div>

This is more of a REPL tip. In a script/program, you will be allocating objects mostly inside scopes and these will be freed when the GC makes a pass and see the objects became inaccessible. Just don’t go crazy with global variables (as they never become inaccessible).
