# Can I have some kind of a memory leak when an exception is being thrown?

**URL:** <https://discourse.julialang.org/t/can-i-have-some-kind-of-a-memory-leak-when-an-exception-is-being-thrown/38939>\
**Category:** New to Julia\
**Tags:** question, performance, exception, memory-allocation\
**Created:** [May 7, 2020, 7:04am UTC](https://discourse.julialang.org/t/can-i-have-some-kind-of-a-memory-leak-when-an-exception-is-being-thrown/38939 "2020-05-07T07:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paveloom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paveloom/32/51156_2.png) [@Paveloom](https://discourse.julialang.org/u/Paveloom)\
**Post date:** [May 7, 2020, 7:04am UTC](https://discourse.julialang.org/t/can-i-have-some-kind-of-a-memory-leak-when-an-exception-is-being-thrown/38939/1 "2020-05-07T07:04:39Z")

</div>

For example, suppose I have a struct with some array variables, and I read data in it from a file, variable by variable. What if I throw a custom exception (without catching) after unsuccessful attempt of reading the third array, asking a user to check the data in the file, for instance? Will the data of the first two arrays (and possibly other instantiated objects) be safely released? Should I worry about performance or memory consumption issues, or are there none of such?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [May 7, 2020, 7:20am UTC](https://discourse.julialang.org/t/can-i-have-some-kind-of-a-memory-leak-when-an-exception-is-being-thrown/38939/2 "2020-05-07T07:20:55Z")

</div>

> [@Paveloom](#):
>
> Will the data of the first two arrays (and possibly other instantiated objects) be safely released?

Yes. The garbage collector will at some point handle that.

> [@Paveloom](#):
>
> Should I worry about performance or memory consumption issues, or are there none of such?

Allocating a huge amount of “unnecessary” memory will of course have performance considerations but that doesn’t seem to apply to this case.

---

<div class="post-metadata">

**Author:** ![Paveloom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paveloom/32/51156_2.png) [@Paveloom](https://discourse.julialang.org/u/Paveloom)\
**Post date:** [May 7, 2020, 11:15am UTC](https://discourse.julialang.org/t/can-i-have-some-kind-of-a-memory-leak-when-an-exception-is-being-thrown/38939/3 "2020-05-07T11:15:34Z")

</div>

@kristoffer.carlsson This answer satisfies me, thank you.
