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

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.

Copy-pasted from 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() . Moreover, an attempt to use A will likely result in an error, because most methods are not defined on type Nothing .

2 Likes

Yes, restart Julia.

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

Ctrl-D or exit()

2 Likes

Thanks. I works well.

There is a command “Restart Julia REPL”.

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?

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).

2 Likes