Freeing all Variables, File Handles and Resources inside a Script

Hi,

I am developing a package that, among other things, runs user-defined functions that may allocate data, open an write to files and run external programs. Is there a function similar to workspace() that I can call inside a script to make sure all resources allocated by a function are freed?

In more detail, I need to cleanly rerun user-defined functions multiple times and I would like to know if there is a way to force or make sure that, regarding those function calls, I/O is done, opened files are closed, allocated variables are freed and external programs finished.

Thank you!

In general, no.

Thanks for answering. Do you know if there is a way to check if all external programs are finished? That would already help, I guess. I think an easier solution for a general case would be implementing some kind of cleanup callback.

Maybe you could use the parallel computing routines as a way of putting user-defined functions in their own process?
https://docs.julialang.org/en/stable/manual/parallel-computing/