How does one clear or remove a global in julia?

Mateo picture Mateo · Mar 25, 2014 · Viewed 21.3k times · Source

Is there any syntax that does something similar to MATLAB's "clear" i.e. if I have a global variable "a". How do I get rid of it? How do I do the analog of

clear a

Answer

tholy picture tholy · Mar 26, 2014

See the latest answer to this question here: https://docs.julialang.org/en/v1/manual/faq/#How-do-I-delete-an-object-in-memory%3F

Retrieved from the docs:

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 = 0. The memory will be released the next time the garbage collector runs; you can force this to happen with gc().