OutOfMemory(): How to inspect environment memory?

I run into an OutOfMemory error when running an algorithm several times. Everything happens inside functions so I don’t understand why and I would like to inspect what has accumulated in the memory. The error is triggered on a push!(::Vector, x). I see in my task manager that the julia process suddenly takes 6Gb of memory when I spam the algorithm.

Unfortunately, the environment pane in Juno does not show that anything is taking more space.

I would help if you post some code. This error can happen for many reasons.

1 Like

Yes I know, but it’s 500 lines of code I can’t really show a MWE unfortunately. I can paste the stacktrace though:

ERROR: LoadError: OutOfMemoryError()
Stacktrace:
 [1] push! at ./array.jl:827 [inlined]
 [2] backward_SDP(::InventoryModels.Scarf.Instance{Float64}, ::Float64) at /home/dehaybe/OneDrive/Doctorat/DRL_SIP/src/InventoryModels/src/Scarf.jl:135
 [3] backward_SDP(::InventoryModels.Scarf.Instance{Float64}) at /home/dehaybe/OneDrive/Doctorat/DRL_SIP/src/InventoryModels/src/Scarf.jl:116
 [4] macro expansion at /home/dehaybe/OneDrive/Doctorat/DRL_SIP/scripts/hyperparameter_tuning.jl:59 [inlined]
 [5] (::var"#15#18"{Hyperoptimizer})(::Symbol) at /home/dehaybe/.julia/packages/Hyperopt/YyteE/src/Hyperopt.jl:82
 [6] #progress#2(::String, ::typeof(Juno.progress), ::var"#15#18"{Hyperoptimizer}) at /home/dehaybe/.julia/packages/Juno/f8hj2/src/progress.jl:35
 [7] progress at /home/dehaybe/.julia/packages/Juno/f8hj2/src/progress.jl:32 [inlined]
 [8] macro expansion at /home/dehaybe/.julia/packages/Hyperopt/YyteE/src/Hyperopt.jl:80 [inlined]
 [9] tune() at /home/dehaybe/OneDrive/Doctorat/DRL_SIP/scripts/hyperparameter_tuning.jl:25
 [10] top-level scope at /home/dehaybe/OneDrive/Doctorat/DRL_SIP/scripts/hyperparameter_tuning.jl:105
 [11] include at ./boot.jl:328 [inlined]
 [12] include_relative(::Module, ::String) at ./loading.jl:1105
 [13] include(::Module, ::String) at ./Base.jl:31
 [14] include(::String) at ./client.jl:424
 [15] top-level scope at REPL[1]:1

Unfortunately, from that message, the only thing we can infer, I think, is that you are trying to allocate in the push! an array that does not fit in the available memory.

1 Like

Can you run it with less input? Or maybe stop execution before it’s done? If you could start julia with “–track-allocation=user” to see where most of the memory is being allocated. That might work even with the crash, you just need to terminate julia (Crtl D) to have it write out the allocations.

You can also use the functions sizeof and Base.summarysize to print out the size of the objects in your function. Start with a small input so it dosn’t crash. Increase your input by a magnitude and see the growth in memory size.

I recently had out of memory errors, particularly with a matrix 100,000 x 100,000. The element type of this array was Int64. I was only story the numbers 1 to 8 for each element, and substantially reduced my memory consumption by changing the type of each element to Int16.

I actually don’t know whether that affects performance or not (something to do with 64 bit machines and optimal CPU utilization), but it worked for my case.

In this case [U]Int8 would be also enough, reducing the size by a factor of two.

@HenriDeh I recommend reading the section about profiling: Profiling · The Julia Language this will help you find the problematic lines and functions.

Hello all,

Thank you for your answers. It turned out that some arguments would make an infinite loop. This was more a mathematical issue in the end.

1 Like