# How to deal with Julia Out of memory problem

**URL:** <https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140>\
**Category:** General Usage\
**Created:** [April 28, 2021, 2:43am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140 "2021-04-28T02:43:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![james1](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@james1](https://discourse.julialang.org/u/james1)\
**Post date:** [April 28, 2021, 2:43am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/1 "2021-04-28T02:43:40Z")

</div>

LoadError: OutOfMemoryError()  
in expression starting at C:\Users\12984\Desktop\Interaction.jl:123

When I ran the program, I ran out of memory, as shown in the above statement. I tried to clean up the previous saved variable, but I don’t know how to do it, I hope someone can help me

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 28, 2021, 3:43am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/2 "2021-04-28T03:43:52Z")

</div>

Welcome to our community 🎊

There is nothing much you can do after Julia triggers an `OutOfMemory`. If this happens inside a `try`–`catch` block, then there is some chance Julia will be able the capture it and (also depending on some luck) after you get out of the block the objects that caused the problem will be out of scope and have been freed already.

> clean up the previous saved variable, but I don’t know how to do it

There is no simple way to just freeing a Julia object so I am not sure of what you tried. You can assign `nothing` to it and then call `Base.GC.gc(true)` but this will likely take some time and, in meantime, probably will allocate some memory.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 28, 2021, 4:32am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/3 "2021-04-28T04:32:02Z")

</div>

@james1 Welcome to Julia! Everyone here is very helpful.  
What computer type are you running this on - and how much memory does it have.  
What program are you running? Is this using a REPL session?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 28, 2021, 9:00am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/4 "2021-04-28T09:00:13Z")

</div>

This could have many causes and consequently various solutions (including “buy more RAM” 😉). Please post an MWE that reproduces the error.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![doit](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@doit](https://discourse.julialang.org/u/doit)\
**Post date:** [April 28, 2021, 9:41am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/5 "2021-04-28T09:41:14Z")

</div>

I had a similar problem between function calls, within which I loaded a large dataset (requiring roughly 90% of RAM). Initially, I thought the garbage collector would automatically free memory once the function scope was left but this was not the case.  
Manually triggering GC between function calls via GC.gc() helped in this case. The function evaluation would take hours so GC would not be a bottleneck. Otherwise, the equivalent approach by @Henrique_Becker (if you do not leave scope) should work.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 28, 2021, 11:40am UTC](https://discourse.julialang.org/t/how-to-deal-with-julia-out-of-memory-problem/60140/6 "2021-04-28T11:40:58Z")

</div>

As Tamas said, providing a working example will get you better help. It is possible that you can completely avoid the allocation of that memory to begin with.
