Investigate PKG_DEL scripts
its
pkg unload's fault for not giving us a hook
Not sure what exactly you need. But the PKG_DEL scripts might do something similar. See: https://docs.octave.org/latest/Creating-Packages.html
Essentially, these scripts are executed whenever the path containing them is removed from Octave's load path. That is happening on pkg unload. (But admittedly, it's not a real hook but just a script.)
Maybe you could use (mlocked) functions that keep some values stored in persistent variables if you need to access them from the PKG_DEL script?
Originally posted by @mmuetzel in https://github.com/cbm755/octsympy/issues/1175#issuecomment-1175083790
In the future, we should investigate whether to trigger cleanup in PKG_DEL script. This could simplify our current approach.