Next: Hooks for Loading, Previous: Where Defined, Up: Loading
You can discard the functions and variables loaded by a library to
reclaim memory for other Lisp objects. To do this, use the function
unload-feature:
This command unloads the library that provided feature feature. It undefines all functions, macros, and variables defined in that library with
defun,defalias,defsubst,defmacro,defconst,defvar, anddefcustom. It then restores any autoloads formerly associated with those symbols. (Loading saves these in theautoloadproperty of the symbol.)Before restoring the previous definitions,
unload-featurerunsremove-hookto remove functions in the library from certain hooks. These hooks include variables whose names end in `hook' or `-hooks', plus those listed inunload-feature-special-hooks. This is to prevent Emacs from ceasing to function because important hooks refer to functions that are no longer defined.If these measures are not sufficient to prevent malfunction, a library can define an explicit unload hook. If feature
-unload-hookis defined, it is run as a normal hook before restoring the previous definitions, instead of the usual hook-removing actions. The unload hook ought to undo all the global state changes made by the library that might cease to work once the library is unloaded.unload-featurecan cause problems with libraries that fail to do this, so it should be used with caution.Ordinarily,
unload-featurerefuses to unload a library on which other loaded libraries depend. (A library a depends on library b if a contains arequirefor b.) If the optional argument force is non-nil, dependencies are ignored and you can unload any library.
The unload-feature function is written in Lisp; its actions are
based on the variable load-history.
This variable holds a list of hooks to be scanned before unloading a library, to remove functions defined in the library.
