How to deal with Julia Out of memory problem

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

1 Like

Welcome to our community :confetti_ball:

There is nothing much you can do after Julia triggers an OutOfMemory. If this happens inside a trycatch 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.


@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?

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


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.

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.

1 Like