Often new users face problems with lingering definitions that, if unaware, may cause unexpected and frustrating behaviour.
There are several answers that illustrate different aspects of the solution, but not a single place that can serve as a guide where the best strategies are compared side by side.
For example, in this answer @celtschk points to the need of using
ClearAll[Evaluate[$Context <> "*"]]
instead of
ClearAll["Global`*"]
in the cases when the Notebook has a Context set to "unique to this Notebook".
This answer by @LeonidShifrin compares Remove versus ClearAll.
In this other answer @Szabolcs gives an extensive explanation to the "significant practical differences" between Quit versus ClearAll["Global`*"].
And here @C.E. points to the use of
Needs["Utilities`CleanSlate`"]
CleanSlate[];
ClearInOut[];
Ultimately the advice seems to come to actually closing the kernel and starting one fresh, either via Exit or Quit.
Quit[]
But that doesn't cover preventive measures nor the possibility of a Dynamic cell in the notebook, or initialization commands or any other mechanism that could re-spawn definitions.
Here I'm hoping for a canonical guide to the problem of a fresh kernel.




f[g[h[x]]]quite often but I found it could make my code quite unintelligible / less obvious. I now try to make my intentions more obvious by introducing variables in each step of calculation but as addressed in this post I end up with lots of lingering variables. Are there any thoughts/guides on best practice in dealing with this tension? – IntroductionToProbability Nov 07 '22 at 11:31Module. Creating variables is not forbidden, you just need to be aware of the alternatives and compromises you are making by choosing one. – rhermans Nov 07 '22 at 11:43Moduleoften in function definitions but almost never as a pure scoping construct. I will change this in future to avoid lingering variables over large notebooks. – IntroductionToProbability Nov 07 '22 at 11:52