# Freeing all Variables, File Handles and Resources inside a Script

**URL:** <https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 23, 2017, 1:24am UTC](https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867 "2017-05-23T01:24:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phrb/32/13580_2.png) [@phrb](https://discourse.julialang.org/u/phrb)\
**Post date:** [May 23, 2017, 1:24am UTC](https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867/1 "2017-05-23T01:24:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [May 23, 2017, 1:36am UTC](https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867/2 "2017-05-23T01:36:35Z")

</div>

In general, no.

---

<div class="post-metadata">

**Author:** ![phrb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phrb/32/13580_2.png) [@phrb](https://discourse.julialang.org/u/phrb)\
**Post date:** [May 23, 2017, 8:24pm UTC](https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867/3 "2017-05-23T20:24:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [May 24, 2017, 5:08am UTC](https://discourse.julialang.org/t/freeing-all-variables-file-handles-and-resources-inside-a-script/3867/4 "2017-05-24T05:08:42Z")

</div>

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/](https://docs.julialang.org/en/stable/manual/parallel-computing/)
