# Extreme memory usage in nested loop

**URL:** <https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471>\
**Category:** Performance\
**Tags:** memory-allocation, loops\
**Created:** [September 2, 2023, 11:19pm UTC](https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471 "2023-09-02T23:19:28Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [September 3, 2023, 1:05pm UTC](https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471/9 "2023-09-03T13:05:41Z")

</div>

If the function you are calling uses threads, this problem may be related to 1.9’s memory management issues (supposedly to be resolved in 1.10, some say). Cf:

> [@Understanding memory usage in Julia](https://discourse.julialang.org/t/understanding-memory-usage-in-julia/101647):
>
> I am working on a finite element program that solves a non linear problem by incrementing the boundary conditions, that means that from time to time I need to assemble some quite large stiffness matrices (\approx 350k \times 350k) and solve linear algebra problems. I am surprised of how much memory the program actually uses compared to what I expected and I am trying to understand why that is happening. Before starting the main loop of the program, after the mesh has been read from the input f…

> [@Is there a way to limit memory as reported by Sys.total\_memory()?](https://discourse.julialang.org/t/is-there-a-way-to-limit-memory-as-reported-by-sys-total-memory/93909):
>
> I am trying to run my Julia code on a computing cluster running SLURM. It runs just fine on my own pc, but whenever I try to run it on the cluster (even when I give it the same amount of total memory), my job gets canceled because it uses too much memory. I am thinking the reason is that julia thinks it has access to all of the memory on the compute node (Sys.total\_memory() always shows the total memory of the node, not the amount I assign to the job). As a result, it runs GC too infrequently. I…

---

_[View the full topic](https://discourse.julialang.org/t/extreme-memory-usage-in-nested-loop/103471)._
