Quit
erases all the definitions (by quitting the kernel), but so does ClearAll["Global`*"]
(or other contexts). What's the difference in terms of variables in the notebook?
1 Answer
There are significant practical differences.
Quit
does not "clear" anything, it instead restarts the kernel, i.e. resets it to the default state. There is a lot of internal state that changes during the session in ways that are different from creating new symbols or attaching definitions. So simply clearing (or removing) symbols won't reset the kernel. Examples include:
When you load a package, it does not only create its own context, it also causes
$Context
and$Packages
to be modifiedSymbolic results are cached (
ClearSystemCache
) and will actually cause symbolic processing functions to return different results than they would in a fresh session.$ModuleNumber
changesDirectory[]
changespseudo-random number generator states change (and this also involves caching behind the scenes, which in principle affects memory usage)
Logins to various services (e.g.
SocialMediaData
) may be remembered until the end of the sessionIn
/Out
/$Line
changeParallel kernels keep running,
ParallelNeeds
keeps remembering "needed" packages,DistributeDefinitions
keeps remembering what was distributedA fresh kernel doesn't have all symbol definitions loaded. Using various symbols triggers loading definition and triggers loading packages.
etc.
These are just a few random but concrete examples that came to mind. This list is not at all meant to be exhaustive, it is simply to illustrate how many things get modified during a session. There are many more than these, very likely including many which concern the internal workings of Mathematica and we don't even know about (as they are not publicly documented).
This is all in addition to the difference between Remove
and ClearAll
which people mentioned in the comments and which is also significant (e.g. ClearAll
won't help with shadowing but Remove
will).
In short, if you are having trouble with Mathematica, reset it fully by restarting the kernel, don't just clear your own definitions.
Quit
has the effect ofRemove
, which "removes symbols completely, so that their names are no longer recognized by the Wolfram Language." In contrast,ClearAll
"clears all values, definitions, attributes, messages, and defaults associated with symbols." Following the documentation, seta = 3
, runQuit
,Remove
,ClearAll
, etc, and then execute?a
. $\endgroup$ClearAll["Global`*"]
, try runningNames["Global`*"]
. Repeat the experiment, replacingClearAll[]
withRemove[]
. $\endgroup$ClearAll
means? Does it signify anything? $\endgroup$ClearAll
and then executeDumpsave
what will it save in .mx file? $\endgroup$