# Clearing out a package

I'm just beginning with packages, so this is definitely a beginner's question. Suppose that I do this in a notebook:

BeginPackage["David"]
$Context$ContextPath
EndPackage[]
$Context$ContextPath


The output is:

 "David"
"David"
{"David", "System"}
"Global"
{"David", "WolframAlphaClient", "IconizeLoader", "HTTPHandlingLoader",
"StreamingLoader", "InterpreterLoader", "CloudObjectLoader",
"PacletManager", "System", "Global"}


Note that "David" is the first on the $ContextPath. Now, my question is, how to clear. I know one way is to simply quit the kernel with Quit. I also did a little searching and tried this: $ContextPath = DeleteCases[$ContextPath, "David"]  The output is: {"WolframAlphaClient", "IconizeLoader", "HTTPHandlingLoader", "StreamingLoader", "InterpreterLoader", "CloudObjectLoader", "PacletManager", "System", "Global"}  So "David" has been removed from the $ContextPath, so any functions or symbols created in the package (I did none) will not be found unless I put in their "long" name (such as Davidtotal`). Am I correct?

But I am thinking this might not be enough, so I'd like to ask my colleagues "How do you clear a package?"

• There is no way to fully 'clear a package'. Once it's loaded, it stays loaded until you restart the kernel. What exactly are you trying to achieve? Jul 1 '17 at 5:33
• The most sure way to clear a package is to quit the kernel. There used to be cleanSlate package to fully clear package without restarting kernel, but I do not know if it is still supported on newer versions. Jul 1 '17 at 7:10
• To be clearer, returning the kernel to the exact state before loading the package is not realistic. But most of the aspects of unloading that are desired in practice (such as not having the package context in the context path) are achievable. However, no method is going to be completely robust, as many details depend on what the particular package does. Jul 1 '17 at 13:17