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?
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 if fully by restarting the kernel, don't just clear your own definitions.
Comments
Post a Comment