How to clear variables and/or whole work space

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

function unbindvariables()
    for name in names(Main)
        if !isconst(Main, name)
            Main.eval(:($name = nothing))
        end
    end
end
2 Likes