# \#memory-allocation

**URL:** https://discourse.julialang.org/tag/memory-allocation/159.md?page=1

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 2

---

## [How to track total memory usage of Julia process over time](https://discourse.julialang.org/t/how-to-track-total-memory-usage-of-julia-process-over-time/91167)

<div class="topic-metadata">

**Author:** [@sloede](https://discourse.julialang.org/u/sloede)\
**Replies:** 17\
**Last updated:** [June 6, 2025, 9:34pm UTC](https://discourse.julialang.org/t/how-to-track-total-memory-usage-of-julia-process-over-time/91167 "2025-06-06T21:34:01Z")

</div>

What is a good tool to track the memory usage of the Julia process over time? Ideally, I would like to find out how much memory is used by Julia at any given time, especially at peak times during, e.g., compilation, but …

---

## [Allocations when moving loop into a function](https://discourse.julialang.org/t/allocations-when-moving-loop-into-a-function/129534)

<div class="topic-metadata">

**Author:** [@omicron8](https://discourse.julialang.org/u/omicron8)\
**Replies:** 3\
**Last updated:** [June 1, 2025, 10:04pm UTC](https://discourse.julialang.org/t/allocations-when-moving-loop-into-a-function/129534 "2025-06-01T22:04:08Z")

</div>

Why does the first variant (function foo) allocate a large amount of memory while the second variant (function bar) does not? The difference is whether the loop is inside or outside the function. Is there a way to have t…

---

## [Reducing allocations](https://discourse.julialang.org/t/reducing-allocations/129415)

<div class="topic-metadata">

**Author:** [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Replies:** 44\
**Last updated:** [May 31, 2025, 3:12pm UTC](https://discourse.julialang.org/t/reducing-allocations/129415 "2025-05-31T15:12:26Z")

</div>

I have a function that is going to be called many hundreds of thousands of times so I want it optimized maximally. To reduce allocations, I decided I would create a struct the stored some buffer arrays, then I would ass…

---

## [Why does runtime dispatch allocate when the return type is inferred?](https://discourse.julialang.org/t/why-does-runtime-dispatch-allocate-when-the-return-type-is-inferred/129061)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 5\
**Last updated:** [May 17, 2025, 2:00am UTC](https://discourse.julialang.org/t/why-does-runtime-dispatch-allocate-when-the-return-type-is-inferred/129061 "2025-05-17T02:00:25Z")

</div>

The usual explanation for why runtime dispatches allocate is that falling back to inferring ::Any for the return type requires boxing the instance at runtime. Thing is, there seems to be a workaround. If the compiler kno…

---

## [How to avoid memory allocation while doing sum on a GPU?](https://discourse.julialang.org/t/how-to-avoid-memory-allocation-while-doing-sum-on-a-gpu/128225)

<div class="topic-metadata">

**Author:** [@Shashank](https://discourse.julialang.org/u/Shashank)\
**Replies:** 7\
**Last updated:** [April 20, 2025, 7:00am UTC](https://discourse.julialang.org/t/how-to-avoid-memory-allocation-while-doing-sum-on-a-gpu/128225 "2025-04-20T07:00:48Z")

</div>

I have been having a problem with memory allocation when using sum on a CUDA array. Is there a way to avoid it? I have pasted the relevant parts of the code below: println("3:", CUDA.memory\_status()) Cgain1\_reshaped\_for…

---

## [Large memory consumption when using Mooncake via DifferentiationInterface for Gaussian process optimisation](https://discourse.julialang.org/t/large-memory-consumption-when-using-mooncake-via-differentiationinterface-for-gaussian-process-optimisation/127289)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 19\
**Last updated:** [April 15, 2025, 7:20am UTC](https://discourse.julialang.org/t/large-memory-consumption-when-using-mooncake-via-differentiationinterface-for-gaussian-process-optimisation/127289 "2025-04-15T07:20:30Z")

</div>

Hello everyone, I am working on a model called the Gaussian process latent variable model (GPLVM). The GPLVM is a dimensionality reduction method which given a high dimensional dataset Y will return low-dimensional proj…

---

## [Kwargs allocating (?)](https://discourse.julialang.org/t/kwargs-allocating/127326)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 6\
**Last updated:** [March 27, 2025, 4:21am UTC](https://discourse.julialang.org/t/kwargs-allocating/127326 "2025-03-27T04:21:00Z")

</div>

Hi there, consider the following simple function: M = \[1.0 2.0; 3.0 4.0\] n = size(M,1) I\_n = Matrix{Float64}(I, n, n) A\_temp = zeros(n, n) diff\_temp = zeros(n, n) function inf\_norm\_dif…

---

## [Why is this code allocating?](https://discourse.julialang.org/t/why-is-this-code-allocating/127175)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [March 20, 2025, 2:48pm UTC](https://discourse.julialang.org/t/why-is-this-code-allocating/127175 "2025-03-20T14:48:07Z")

</div>

Why is the following code allocating: using VortexStepMethod # Step 1: Define wing parameters n\_panels = 20 # Number of panels span = 20.0 # Wing span \[m\] chord = 1.0 # Chord length \[m\] v…

---

## [Product distribution allocates (a lot)](https://discourse.julialang.org/t/product-distribution-allocates-a-lot/126771)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 9\
**Last updated:** [March 11, 2025, 3:12pm UTC](https://discourse.julialang.org/t/product-distribution-allocates-a-lot/126771 "2025-03-11T15:12:17Z")

</div>

Hi, I just found out that in the following example, sampling from a Distributions.Product distribution is much slower and allocates much more than implementing the sampler manually. Is there something that I’m overlookin…

---

## [\[ANN\] AlignedAllocs.jl - lightweight cross-platform allocation of aligned memory](https://discourse.julialang.org/t/ann-alignedallocs-jl-lightweight-cross-platform-allocation-of-aligned-memory/126772)

<div class="topic-metadata">

**Author:** [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Replies:** 0\
**Last updated:** [March 10, 2025, 3:39pm UTC](https://discourse.julialang.org/t/ann-alignedallocs-jl-lightweight-cross-platform-allocation-of-aligned-memory/126772 "2025-03-10T15:39:18Z")

</div>

This is a very lightweight cross-platform package that exports two functions, each is an aligned memory allocator. memalign(item\_type, item\_count \[, byte\_alignment\]) providing uninitialized memory memalign\_clear(i…

---

## [Understanding AbstractFloat Arrays](https://discourse.julialang.org/t/understanding-abstractfloat-arrays/126374)

<div class="topic-metadata">

**Author:** [@Luis\_Alberto\_R](https://discourse.julialang.org/u/Luis_Alberto_R)\
**Replies:** 6\
**Last updated:** [February 27, 2025, 9:48pm UTC](https://discourse.julialang.org/t/understanding-abstractfloat-arrays/126374 "2025-02-27T21:48:24Z")

</div>

I’m having a hard time understanding the size (in bytes) of Arrays with AbstractFloat types because of the following: julia\> ar1 = Array{AbstractFloat,3}(rand(50,50,50)); julia\> ar2 = Array{Float64,3}(rand(50,50,50)); …

---

## [How to quantitatively analyze the impact of memory bandwidth on multithreading](https://discourse.julialang.org/t/how-to-quantitatively-analyze-the-impact-of-memory-bandwidth-on-multithreading/125059)

<div class="topic-metadata">

**Author:** [@quantumdreamer](https://discourse.julialang.org/u/quantumdreamer)\
**Replies:** 10\
**Last updated:** [February 6, 2025, 3:20am UTC](https://discourse.julialang.org/t/how-to-quantitatively-analyze-the-impact-of-memory-bandwidth-on-multithreading/125059 "2025-02-06T03:20:15Z")

</div>

When I increased the number of threads in my Julia project, I noticed that the performance of the project did not scale linearly with the number of threads. Currently, the multi-threaded performance is twice that of the …

---

## [Check if vector lies between two vectors element-wise, allocation free](https://discourse.julialang.org/t/check-if-vector-lies-between-two-vectors-element-wise-allocation-free/125537)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 2\
**Last updated:** [February 4, 2025, 5:10pm UTC](https://discourse.julialang.org/t/check-if-vector-lies-between-two-vectors-element-wise-allocation-free/125537 "2025-02-04T17:10:56Z")

</div>

I found some time to profile my code with the intention of reducing memory use and number of allocations. A quick check revealed that the function check\_inequalities was the main culprit for the allocations: in my bigger…

---

## [Unclear allocation behaviour with built-in sum()](https://discourse.julialang.org/t/unclear-allocation-behaviour-with-built-in-sum/125304)

<div class="topic-metadata">

**Author:** [@Deceneu](https://discourse.julialang.org/u/Deceneu)\
**Replies:** 4\
**Last updated:** [February 2, 2025, 1:04am UTC](https://discourse.julialang.org/t/unclear-allocation-behaviour-with-built-in-sum/125304 "2025-02-02T01:04:34Z")

</div>

Hello, Introduction I’ve been trying to process some data and I’ve encountered crippling allocation when using the built-in sum(). I have some mid-level understanding of how to increase performance in Julia, but regardi…

---

## [Can I manage the memory by myself?](https://discourse.julialang.org/t/can-i-manage-the-memory-by-myself/97250)

<div class="topic-metadata">

**Author:** [@zhijie\_sun](https://discourse.julialang.org/u/zhijie_sun)\
**Replies:** 16\
**Last updated:** [February 1, 2025, 7:03pm UTC](https://discourse.julialang.org/t/can-i-manage-the-memory-by-myself/97250 "2025-02-01T19:03:19Z")

</div>

I have a code, the GC live and RSS memory increased quickly when running, while I don’t need such big memory to do basic computation. I need to allocate lots of small dict for intermidiate computing before, and the memor…

---

## [Tools to help catch use of uninitialized memory?](https://discourse.julialang.org/t/tools-to-help-catch-use-of-uninitialized-memory/124231)

<div class="topic-metadata">

**Author:** [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Replies:** 6\
**Last updated:** [January 26, 2025, 10:58pm UTC](https://discourse.julialang.org/t/tools-to-help-catch-use-of-uninitialized-memory/124231 "2025-01-26T22:58:55Z")

</div>

It is easy to accidentally read from uninitialized memory after using resize! to grow a vector. Is there an equivalent of the memory sanitizer in C or any other tools for catching this when testing?

---

## [How to get rid of allocations in this simple filtered generator example?](https://discourse.julialang.org/t/how-to-get-rid-of-allocations-in-this-simple-filtered-generator-example/124847)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 3\
**Last updated:** [January 22, 2025, 6:45pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-allocations-in-this-simple-filtered-generator-example/124847 "2025-01-22T18:45:43Z")

</div>

Here’s a MWE of the allocating code (Julia 1.11.2): function foo() arr = \[Ref(i) for i=1:100\] iter = (i for i in arr if rand()\>0) @time begin elem, state = iterate(iter) while true …

---

## [Help with reducing allocations when indexing into custom Array](https://discourse.julialang.org/t/help-with-reducing-allocations-when-indexing-into-custom-array/124732)

<div class="topic-metadata">

**Author:** [@thomasc791](https://discourse.julialang.org/u/thomasc791)\
**Replies:** 10\
**Last updated:** [January 14, 2025, 10:21pm UTC](https://discourse.julialang.org/t/help-with-reducing-allocations-when-indexing-into-custom-array/124732 "2025-01-14T22:21:09Z")

</div>

Hi everyone, I am quite new to the language, and was wondering if people could help me optimising my piece of code. The idea for this array type is to reduce the total Base.summarysize for a vector of vector as much as …

---

## [Passing a Julia struct to a already compiled cpp program](https://discourse.julialang.org/t/passing-a-julia-struct-to-a-already-compiled-cpp-program/124731)

<div class="topic-metadata">

**Author:** [@TheBreadFarmer](https://discourse.julialang.org/u/TheBreadFarmer)\
**Replies:** 1\
**Last updated:** [January 13, 2025, 6:01pm UTC](https://discourse.julialang.org/t/passing-a-julia-struct-to-a-already-compiled-cpp-program/124731 "2025-01-13T18:01:10Z")

</div>

I am writing a program in Julia that reads data from a file into memory. I’d like to take that data and somehow pass it to a c++ program which will make use of OpenGL to draw that data to the screen. I am making use of …

---

## [How is it possible that parallelized code causes fewer allocations?](https://discourse.julialang.org/t/how-is-it-possible-that-parallelized-code-causes-fewer-allocations/124161)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 19\
**Last updated:** [December 30, 2024, 5:41pm UTC](https://discourse.julialang.org/t/how-is-it-possible-that-parallelized-code-causes-fewer-allocations/124161 "2024-12-30T17:41:58Z")

</div>

This case baffles me: using StructArrays n, s = 10^5, 100; llp = \[rand(1:n,s) for \_=1:n\]; llw = \[rand(-1:0.001:1,s) for \_=1:n\] function sort\_vec!(pp::Vector{tp}, ww::Vector{tw}, by::Function=first) ::Nothing where {tp\<…

---

## [Getting rid of ForwardDiff.jacobian! allocations when using closures](https://discourse.julialang.org/t/getting-rid-of-forwarddiff-jacobian-allocations-when-using-closures/123939)

<div class="topic-metadata">

**Author:** [@franckgaga](https://discourse.julialang.org/u/franckgaga)\
**Replies:** 6\
**Last updated:** [December 19, 2024, 7:30pm UTC](https://discourse.julialang.org/t/getting-rid-of-forwarddiff-jacobian-allocations-when-using-closures/123939 "2024-12-19T19:30:38Z")

</div>

I’m trying to get rid of the memory allocations in jacobian!. For this, I need to pass a cfg argument with a pre-allocated JacobianConfig to the function. According to the doc, its constructor expects to receive the func…

---

## [OutOfMemoryError in HomotopyContinuation](https://discourse.julialang.org/t/outofmemoryerror-in-homotopycontinuation/95105)

<div class="topic-metadata">

**Author:** [@Ricardo\_Miranda\_Mart](https://discourse.julialang.org/u/Ricardo_Miranda_Mart)\
**Replies:** 1\
**Last updated:** [December 19, 2024, 1:28am UTC](https://discourse.julialang.org/t/outofmemoryerror-in-homotopycontinuation/95105 "2024-12-19T01:28:28Z")

</div>

Hi all, I’m trying to use HomotopyContinuation.jl to find all of the solutions a polynomial system of equations with 14 polynomials in 14 variables. Each polynomial is sum of monomials of degree from 10 to 13 (like f1=…

---

## [Removing allocations from ForwardDiff.jacobian!](https://discourse.julialang.org/t/removing-allocations-from-forwarddiff-jacobian/80996)

<div class="topic-metadata">

**Author:** [@jbu](https://discourse.julialang.org/u/jbu)\
**Replies:** 1\
**Last updated:** [December 18, 2024, 10:10pm UTC](https://discourse.julialang.org/t/removing-allocations-from-forwarddiff-jacobian/80996 "2024-12-18T22:10:18Z")

</div>

I’m getting a few stray allocations while using ForwardDiff.jacobian!. I followed the advice in this post, but that didn’t seem to remove them. What’s the best way to track down and eliminate these allocations? Edit: I’…

---

## [Why Base.summarysize show pointers twice?](https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887)

<div class="topic-metadata">

**Author:** [@garazha-ilya](https://discourse.julialang.org/u/garazha-ilya)\
**Replies:** 1\
**Last updated:** [December 16, 2024, 4:23pm UTC](https://discourse.julialang.org/t/why-base-summarysize-show-pointers-twice/123887 "2024-12-16T16:23:21Z")

</div>

Suppose I have string “Moscow”: julia\> Moscow = "Moscow" "Moscow" julia\> sizeof(Moscow) 6 julia\> Base.summarysize(Moscow) 14 I suppose, that 14 = (Pointer to Array of Chars (8 bytes)) + (6 data bytes). However, when I…

---

## [Static array multiplied by its adjoint seems to allocate](https://discourse.julialang.org/t/static-array-multiplied-by-its-adjoint-seems-to-allocate/123232)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 12\
**Last updated:** [December 2, 2024, 3:54pm UTC](https://discourse.julialang.org/t/static-array-multiplied-by-its-adjoint-seems-to-allocate/123232 "2024-12-02T15:54:39Z")

</div>

Hi there, I am writing out a likelihood estimation and I have run into some allocation issues when coding up the Hessian. Even though the Hessian function HLL seems to mirror what the gradient function ∇LL is doing. One…

---

## [Getting different allocations from \`@allocations\` vs \`@timev\`/\`@time\`](https://discourse.julialang.org/t/getting-different-allocations-from-allocations-vs-timev-time/123222)

<div class="topic-metadata">

**Author:** [@sadish-d](https://discourse.julialang.org/u/sadish-d)\
**Replies:** 1\
**Last updated:** [November 28, 2024, 6:55pm UTC](https://discourse.julialang.org/t/getting-different-allocations-from-allocations-vs-timev-time/123222 "2024-11-28T18:55:22Z")

</div>

I have a function f() = Int\[\]. Let’s try and check how much it allocates using @timev (or @time) and @allocations. julia\> @timev f() 0.000002 seconds (1 allocation: 64 bytes) elapsed time (ns): 1667 gc time (ns): …

---

## [Allocations when using getfield with a tuple/vector of symbols](https://discourse.julialang.org/t/allocations-when-using-getfield-with-a-tuple-vector-of-symbols/122756)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 12\
**Last updated:** [November 20, 2024, 2:45am UTC](https://discourse.julialang.org/t/allocations-when-using-getfield-with-a-tuple-vector-of-symbols/122756 "2024-11-20T02:45:24Z")

</div>

MWE: using Parameters, BenchmarkTools @with\_kw struct Test A :: String = "A" B :: Int64 = 0 end test = Test() tup = (:A, :B) @btime getfield($test, :A) @btime getfield($test, $tup\[1\]) Is there a way to loop…

---

## [Huge RAM usage with JumpProcesses.jl](https://discourse.julialang.org/t/huge-ram-usage-with-jumpprocesses-jl/122428)

<div class="topic-metadata">

**Author:** [@hhindley](https://discourse.julialang.org/u/hhindley)\
**Replies:** 13\
**Last updated:** [November 11, 2024, 8:18pm UTC](https://discourse.julialang.org/t/huge-ram-usage-with-jumpprocesses-jl/122428 "2024-11-11T20:18:22Z")

</div>

I am running a stochastic model using JumpProcesses.jl. The lowest consistent memory usage I can achieve is between 8-16GB with simulations that take 10-20seconds. I would assume for such an time efficient simulation the…

---

## [Is it possible to avoid these excess allocations when using @batch or @threads?](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 4\
**Last updated:** [November 8, 2024, 10:37am UTC](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208 "2024-11-08T10:37:37Z")

</div>

It took some effort to come up with a short MWE for this issue. The goal is to avoid a few small allocations when mutating (an argument of an inner function) in parallel: MWEusing BenchmarkTools, Parameters, Polyester, …

---

## [How to know when objects are stack or heap allocated](https://discourse.julialang.org/t/how-to-know-when-objects-are-stack-or-heap-allocated/103056)

<div class="topic-metadata">

**Author:** [@opiateblush](https://discourse.julialang.org/u/opiateblush)\
**Replies:** 7\
**Last updated:** [November 8, 2024, 1:12am UTC](https://discourse.julialang.org/t/how-to-know-when-objects-are-stack-or-heap-allocated/103056 "2024-11-08T01:12:20Z")

</div>

I’m currently writing some performance critical code and got a bit confused about stack and heap allocation in Julia. I thought that immutables are usually stack allocated but apparently that is not the case. I’ve made a…

[Previous page](https://discourse.julialang.org/tag/memory-allocation/159.md?match_all_tags=true&tags%5B%5D=memory-allocation)

[Next page](https://discourse.julialang.org/tag/memory-allocation/159.md?match_all_tags=true&page=2&tags%5B%5D=memory-allocation)
