How to clear variables and/or whole work space

hello ,i’m a newcomer. i use Atom as my IDE for julia . How to clear the information in REPL and the variables that i do not need in the work space

2 Likes

I don’t use Atom but in Julia 0.6 REPL, you can use the workspace() function to clear things up.

julia> a = 1
1

julia> a
1

julia> workspace()

julia> a
ERROR: UndefVarError: a not defined

Note that workspace is gone in 0.7, so going forward the only way to clear your workspace is to quit and restart Julia.

2 Likes

I think you can replace your variables with nothing and then garbage collect.

The following shows what I mean:

testbig=rand(10_000,10_000)
testbig=nothing;
gc()
1 Like

But then the binding still exists.

Is that harmful?

Depends on what you want, just saying it’s different from the behavior of workspace().

1 Like

Using workspace() in Juno is a bad idea and will break all sorts of things, so I’d really advise against it.

You can clear the REPL display with Ctrl-J Ctrl-C or by typing clearconsole() into the REPL, however.

1 Like

thank u all very much . i got it.

1 Like

Ctrl+J, Ctrl+C will clear the Console but not the Workspace: the variables and functions created are not cleared.

You can clear the Workspace from the Console by pressing Ctrl+D to end Julia and Enter to start it again. This works reasonably fast.

I am working in Juno/JuliaPro. Is there any other method to clear the Workspace without stopping Julia?

6 Likes

There used to be a workspace() function, but it was removed as it had some problems. I think that the consensus is that stopping and restarting the process is now fast enough for practical purposes.

2 Likes

It is fast when the project doesn’t have many dependencies. But with more dependencies, it takes more time. Is there any method to restart without precompile again?

8 Likes

It does not work with Julia 1.4.2 on Windows 10. According to the documentation Key bindings, it should be Ctrl + L now.

I do not find how to clear variables in that documentation. The workaround is just to restart Julia.

2 Likes

There should be a way to clear workspace. Ctrl+L clears the console but the objects are still there. Restarting is a bad way of doing things.

10 Likes

How about names(Main), then nothing-ing everyting in the list that you want to clear?

This will not work for any consts, also, attributing nothing to a binding is different from it never existing (for example, as you pointed out, it will appear in the output of names).

Ctrl+L to clear the REPL

I have searched for a while and experimenting with CommonRLInterface https://github.com/JuliaReinforcementLearning/CommonRLInterface.jl. There are some mutable variables. I am not an expert in Julia Programming, but I want to clear the whole workspace or delete a mutable variable (which is not allowed for mutable variables as far as I understand it, but in CommonRLInterface it comes from AbstractEnv superclass so I cannot change it).

struct myEnv <: AbstractEnv 

julia> myGridWorld=Nothing
ERROR: invalid redefinition of constant myGridWorld
Stacktrace:
 [1] top-level scope
   @ none:1

I want to clear the whole workspace. So I have to stop julia and restart it again. In addition I have to activate the environment again.

It would help me if there would exist a button or keyshortcut, which automatically resets the workspace, starting a new julia kernel if necessary and activates the last environment (maybe also restarting the code).

see Clear workspace à la Pluto

Thank you @bkamins. As far as I understand there is not a direct solution available, but by using using REPLinModule, one could set a mode for the REPL

using REPLinModule

I am not sure if I understand the post right …