# How to clean up after a package?

Posted 4 years ago
1753 Views
|
|
2 Total Likes
|
 Some packages create temporary files they work with. How can these be cleaned up automatically on kernel exit?Related discussions: I am aware of a number of possible solutions, but in my opinion none of them are good enough for inclusion in a published package. Set $Epilog or write into end.m (which is auto-loaded by $Epilog's default value).This is not good because it is hard to play well with other packages that might also modify this symbol or this file. If packages will commonly start modifying these, there will inevitably be a conflict sooner or later. Mr.Wizard's solution from the first link above. This relies on undocumented behaviour. I am not comfortable including this in a published package. It may break for unexpected reasons or it may break in future versions. I am not generally against using certain udocumented features, but I am not feeling safe enough about relying on this particular behaviour (maybe I'm wrong though). Use LibraryLink's uninitialization. This works, but requires loading a compiled library. This is much too heavyweight for a package that does not already use LibraryLink. Is there a robust solution that is suitable for inclusion in published packages?Why do I believe that there has to be a good way to achieve this? Because the shared libraries that Compile creates automatically with CompilationTarget -> "C" do get cleaned up in exit. There must be a mechanism in place for this.