# \#memory-allocation

**URL:** https://discourse.julialang.org/tag/memory-allocation/159.md

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

---

## [Region-based GC for Julia: worst event pause 4 ms → 55 µs](https://discourse.julialang.org/t/region-based-gc-for-julia-worst-event-pause-4-ms-55-s/139158)

<div class="topic-metadata">

**Author:** [@melevy](https://discourse.julialang.org/u/melevy)\
**Replies:** 8\
**Last updated:** [September 8, 2026, 5:58pm UTC](https://discourse.julialang.org/t/region-based-gc-for-julia-worst-event-pause-4-ms-55-s/139158 "2026-09-08T17:58:13Z")

</div>

I run discrete-event simulations that drive hardware in the loop, which means every event has a deadline of about 100 µs. Julia’s collector is fine on throughput but occasionally it stops the world for milliseconds, an…

---

## [How to understand reasons for some unexpected heap allocations](https://discourse.julialang.org/t/how-to-understand-reasons-for-some-unexpected-heap-allocations/137645)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 25\
**Last updated:** [June 19, 2026, 1:47pm UTC](https://discourse.julialang.org/t/how-to-understand-reasons-for-some-unexpected-heap-allocations/137645 "2026-06-19T13:47:16Z")

</div>

I’m really surprised by some heap allocations being made within a package I maintain. I don’t expect them because: I’ve use Cthulhu to ensure that all variables in the code are concretely typed. The variables in questi…

---

## [Memory allocations in Flux evaluation/training (w/MVE)](https://discourse.julialang.org/t/memory-allocations-in-flux-evaluation-training-w-mve/137175)

<div class="topic-metadata">

**Author:** [@CrashBurnRepeat](https://discourse.julialang.org/u/CrashBurnRepeat)\
**Replies:** 39\
**Last updated:** [June 6, 2026, 10:00am UTC](https://discourse.julialang.org/t/memory-allocations-in-flux-evaluation-training-w-mve/137175 "2026-06-06T10:00:29Z")

</div>

I’m currently using Flux to do some GAN experiments and I’m finding that the training is painfully slow. On the CPU, a single epoch can take ~30min for a 286x32 sample dataloader. GPU evaluation is faster, but still feel…

---

## [ForwardDiff Lie brackets allocate with StaticArrays](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248)

<div class="topic-metadata">

**Author:** [@tremelow](https://discourse.julialang.org/u/tremelow)\
**Replies:** 0\
**Last updated:** [May 22, 2026, 9:34pm UTC](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248 "2026-05-22T21:34:52Z")

</div>

I’m working on a code where I need Lie brackets of Lie brackets, but computing the Jacobian of a Lie bracket allocates data. Here’s a MWE using StaticArrays using BenchmarkTools import ForwardDiff f(x::SVector{2,T}) wh…

---

## [Allocations from scalar arguments in functions](https://discourse.julialang.org/t/allocations-from-scalar-arguments-in-functions/136927)

<div class="topic-metadata">

**Author:** [@Pablo\_Montes](https://discourse.julialang.org/u/Pablo_Montes)\
**Replies:** 3\
**Last updated:** [April 30, 2026, 2:56pm UTC](https://discourse.julialang.org/t/allocations-from-scalar-arguments-in-functions/136927 "2026-04-30T14:56:08Z")

</div>

Hello, I am trying to optimize a code for simulating fluids that is currently allocating massive amounts of memory. I’m focusing on some specific functions that are simple but need to be called repeatedly (thousands of t…

---

## [Reusing @local cache when multithreading](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579)

<div class="topic-metadata">

**Author:** [@amousavi](https://discourse.julialang.org/u/amousavi)\
**Replies:** 1\
**Last updated:** [April 6, 2026, 1:30am UTC](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579 "2026-04-06T01:30:17Z")

</div>

Hi everyone! I am trying to update an old project of mine where I have three nested for loops as such: scratch = zeros(Float32, tree\_nodes, nthreads()) collect\_here = zeros(Float32, nthreads()) for i in eachindex(V) @…

---

## [Contradictory nested function performance and allocation](https://discourse.julialang.org/t/contradictory-nested-function-performance-and-allocation/136548)

<div class="topic-metadata">

**Author:** [@lilachint](https://discourse.julialang.org/u/lilachint)\
**Replies:** 2\
**Last updated:** [April 4, 2026, 8:38am UTC](https://discourse.julialang.org/t/contradictory-nested-function-performance-and-allocation/136548 "2026-04-04T08:38:44Z")

</div>

Recently when working on sorting data with Hilbert curves, I noticed something very peculiar when benchmarking. function hilbert\_sort(m::AbstractMatrix{\<:Integer}, b::Integer; rev::Bool = false) return m\[:, hilbert\_…

---

## [Does \`String(unsafe\_wrap(cstring, len, own=true))\` free the memory it points to?](https://discourse.julialang.org/t/does-string-unsafe-wrap-cstring-len-own-true-free-the-memory-it-points-to/136315)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 2\
**Last updated:** [March 21, 2026, 1:47am UTC](https://discourse.julialang.org/t/does-string-unsafe-wrap-cstring-len-own-true-free-the-memory-it-points-to/136315 "2026-03-21T01:47:02Z")

</div>

If I have a Cstring from a @ccall that I am responsible for freeing, does converting that Cstring to a Julia String via s = String(unsafe\_wrap(Vector{UInt8}, Ptr{UInt8}(cstring), len, own=true)) automatically free the as…

---

## [Why do \`@allocated\` and \`Profile.Allocs.@profile\` give different results?](https://discourse.julialang.org/t/why-do-allocated-and-profile-allocs-profile-give-different-results/134956)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 1\
**Last updated:** [March 10, 2026, 2:52pm UTC](https://discourse.julialang.org/t/why-do-allocated-and-profile-allocs-profile-give-different-results/134956 "2026-03-10T14:52:52Z")

</div>

The number of allocations reported by Profile.Allocs.@profile agrees with @allocations, but the total number of bytes allocated differs from @allocated for some reason: using Profile.Allocs f(n) = sum(2\*collect(1:n)) …

---

## [Combining reshape and view sometimes allocates](https://discourse.julialang.org/t/combining-reshape-and-view-sometimes-allocates/135725)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 2\
**Last updated:** [February 20, 2026, 2:31am UTC](https://discourse.julialang.org/t/combining-reshape-and-view-sometimes-allocates/135725 "2026-02-20T02:31:05Z")

</div>

I have some complicated code that uses a combination of reshape() and view(), and in my complicated code both reshape() and view() allocates. Trying to reduce my code to an MRE, I came up with this: function profile\_all…

---

## [Idiomatic evaluate for scalar, allocate and broadcast for array?](https://discourse.julialang.org/t/idiomatic-evaluate-for-scalar-allocate-and-broadcast-for-array/135147)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [January 21, 2026, 7:01am UTC](https://discourse.julialang.org/t/idiomatic-evaluate-for-scalar-allocate-and-broadcast-for-array/135147 "2026-01-21T07:01:58Z")

</div>

In several cases I’ve come across the following pattern: function f(x; kwargs...) #intense pre-computation that depend on kwargs but not x result = 0.0 \* x; # one way to preallocate for e.g. x::Vector, but not for scala…

---

## [How to efficiently update a Sparse Matrix (Diagonal + Sparse) in-place inside a hot loop?](https://discourse.julialang.org/t/how-to-efficiently-update-a-sparse-matrix-diagonal-sparse-in-place-inside-a-hot-loop/134705)

<div class="topic-metadata">

**Author:** [@Matt\_jl](https://discourse.julialang.org/u/Matt_jl)\
**Replies:** 3\
**Last updated:** [December 23, 2025, 3:51pm UTC](https://discourse.julialang.org/t/how-to-efficiently-update-a-sparse-matrix-diagonal-sparse-in-place-inside-a-hot-loop/134705 "2025-12-23T15:51:57Z")

</div>

Hi everyone, I am working on an iterative algorithm where I need to construct and solve a linear system inside a “hot loop”. Currently, my code allocates a new sparse matrix A at every iteration because of the operati…

---

## [Int -\> Str -\> print(io,\_) without allocations](https://discourse.julialang.org/t/int-str-print-io-without-allocations/134626)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 16\
**Last updated:** [December 19, 2025, 11:53am UTC](https://discourse.julialang.org/t/int-str-print-io-without-allocations/134626 "2025-12-19T11:53:12Z")

</div>

I have billions of Ints that I wish to write to a file. Something similar to mmwrite() in MatrixMarket.jl. I am already using IOBuffer with a large enough sizehint. When I do print(io, n::Int), behind the scenes, a conve…

---

## [Understanding memory usage in Julia](https://discourse.julialang.org/t/understanding-memory-usage-in-julia/101647)

<div class="topic-metadata">

**Author:** [@Andrea\_Vigliotti](https://discourse.julialang.org/u/Andrea_Vigliotti)\
**Replies:** 23\
**Last updated:** [December 12, 2025, 4:30pm UTC](https://discourse.julialang.org/t/understanding-memory-usage-in-julia/101647 "2025-12-12T16:30:39Z")

</div>

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 \\t…

---

## [Remove memory from Julia's management](https://discourse.julialang.org/t/remove-memory-from-julias-management/133983)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 2\
**Last updated:** [November 19, 2025, 12:19pm UTC](https://discourse.julialang.org/t/remove-memory-from-julias-management/133983 "2025-11-19T12:19:01Z")

</div>

When calling into Julia and using it as a library, is it possible to remove an allocated datum from Julia’s management? My use case is this: I have a Julia function, passed across FFI as a callback, which creates data b…

---

## [Memory kills this code](https://discourse.julialang.org/t/memory-kills-this-code/133583)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 5\
**Last updated:** [November 3, 2025, 9:33pm UTC](https://discourse.julialang.org/t/memory-kills-this-code/133583 "2025-11-03T21:33:45Z")

</div>

This code is giving accurate plot but needs too much memory and is slow. I have been working since few months to get 3D volume plot of this Astrophysical data linked here. You can download this data by clicking on Downlo…

---

## [Speeding up Ewald summation](https://discourse.julialang.org/t/speeding-up-ewald-summation/80830)

<div class="topic-metadata">

**Author:** [@dkonstan](https://discourse.julialang.org/u/dkonstan)\
**Replies:** 15\
**Last updated:** [November 3, 2025, 5:41pm UTC](https://discourse.julialang.org/t/speeding-up-ewald-summation/80830 "2025-11-03T17:41:41Z")

</div>

Hi Julia! I am writing a small molecular dynamics engine in Julia to teach myself the language and I noticed that 67% of the time spent running the following Ewald summation function (to calculate coulomb energy of an i…

---

## [\[ANN\] ArenaPirate.jl: proof-of-concept arena allocator (not in the registry)](https://discourse.julialang.org/t/ann-arenapirate-jl-proof-of-concept-arena-allocator-not-in-the-registry/132856)

<div class="topic-metadata">

**Author:** [@artemsolod](https://discourse.julialang.org/u/artemsolod)\
**Replies:** 0\
**Last updated:** [October 3, 2025, 3:20pm UTC](https://discourse.julialang.org/t/ann-arenapirate-jl-proof-of-concept-arena-allocator-not-in-the-registry/132856 "2025-10-03T15:20:35Z")

</div>

repo: https://github.com/artemsolod/ArenaPirate.jl This package redefines Memory{T}(::UndefInitializer, m::Int64) (hence “pirate” in the name) and provides an @arena macro for marking sections of code to be eligible fo…

---

## [Identical method redefinition suspiciously optimizes runtime and allocations](https://discourse.julialang.org/t/identical-method-redefinition-suspiciously-optimizes-runtime-and-allocations/132156)

<div class="topic-metadata">

**Author:** [@afleming](https://discourse.julialang.org/u/afleming)\
**Replies:** 25\
**Last updated:** [September 15, 2025, 12:39am UTC](https://discourse.julialang.org/t/identical-method-redefinition-suspiciously-optimizes-runtime-and-allocations/132156 "2025-09-15T00:39:19Z")

</div>

I am using Revise.jl to work on a package for my research, and am noticing that “revising” a file to identical code with different variable names causes a function to stop allocating. I am not sure how many details othe…

---

## [Why does \`Union{Int,...}\` in a \`Vector\` not cause allocations but \`Union{Float64,...}\` does?](https://discourse.julialang.org/t/why-does-union-int-in-a-vector-not-cause-allocations-but-union-float64-does/132067)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 8\
**Last updated:** [September 3, 2025, 11:44am UTC](https://discourse.julialang.org/t/why-does-union-int-in-a-vector-not-cause-allocations-but-union-float64-does/132067 "2025-09-03T11:44:22Z")

</div>

I have a custom missing type which stores a symbol and a reference to an object whose type is not predetermined, so it’s an Any field. I need to store vectors of these, some values will be missing but most won’t be. Here…

---

## [Unexpected allocations after re-including unchanged file in ODE simulation](https://discourse.julialang.org/t/unexpected-allocations-after-re-including-unchanged-file-in-ode-simulation/131445)

<div class="topic-metadata">

**Author:** [@Vladislav](https://discourse.julialang.org/u/Vladislav)\
**Replies:** 2\
**Last updated:** [August 8, 2025, 4:10am UTC](https://discourse.julialang.org/t/unexpected-allocations-after-re-including-unchanged-file-in-ode-simulation/131445 "2025-08-08T04:10:15Z")

</div>

Hello! I’m running a large number of parallel Monte Carlo simulations, so I’m working to minimize memory allocations in my code. While doing this, I encountered some behavior I don’t fully understand. I’m using Julia V…

---

## [Excessive allocations in basic SciMLSensitivity example](https://discourse.julialang.org/t/excessive-allocations-in-basic-scimlsensitivity-example/131145)

<div class="topic-metadata">

**Author:** [@moble](https://discourse.julialang.org/u/moble)\
**Replies:** 15\
**Last updated:** [July 29, 2025, 7:17pm UTC](https://discourse.julialang.org/t/excessive-allocations-in-basic-scimlsensitivity-example/131145 "2025-07-29T19:17:19Z")

</div>

The first example (copied below) in the SciMLSensitivity docs shows how to optimize the parameters of the Lotka-Volterra system to achieve a steady state. There’s no neural network, or anything, just an ODE system with …

---

## [Memory leaks from compiled functions: Solved](https://discourse.julialang.org/t/memory-leaks-from-compiled-functions-solved/130886)

<div class="topic-metadata">

**Author:** [@Gesee](https://discourse.julialang.org/u/Gesee)\
**Replies:** 18\
**Last updated:** [July 22, 2025, 4:45pm UTC](https://discourse.julialang.org/t/memory-leaks-from-compiled-functions-solved/130886 "2025-07-22T16:45:06Z")

</div>

I have been told about one known issue with Julia, compiled function doesn’t get garbage collected. So since I wanted to dynamically create functions for objects in my game engine, it was a big problem and I had to solve…

---

## [How best to preallocate memory for repeated use](https://discourse.julialang.org/t/how-best-to-preallocate-memory-for-repeated-use/130814)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 5\
**Last updated:** [July 22, 2025, 4:21pm UTC](https://discourse.julialang.org/t/how-best-to-preallocate-memory-for-repeated-use/130814 "2025-07-22T16:21:41Z")

</div>

Hello, I’m trying to reduce memory allocations. The pattern is simple: I need to redo a similar problem that requires a fair bit of memory many times. So I’m preallocating sufficient memory for the largest problem and…

---

## [Fixed-structure CHOLMOD with in-place \`set\_nonzeros!\`](https://discourse.julialang.org/t/fixed-structure-cholmod-with-in-place-set-nonzeros/130922)

<div class="topic-metadata">

**Author:** [@luke-kiernan](https://discourse.julialang.org/u/luke-kiernan)\
**Replies:** 3\
**Last updated:** [July 22, 2025, 3:03am UTC](https://discourse.julialang.org/t/fixed-structure-cholmod-with-in-place-set-nonzeros/130922 "2025-07-22T03:03:22Z")

</div>

I have a large sparse matrix. Its nonzeros change over the course of the problem, but its structure doesn’t. I want to do repeated in-place Cholesky factorizations, re-using the symbolic factorization and modifying the n…

---

## [ForwardDiff Allocations](https://discourse.julialang.org/t/forwarddiff-allocations/130006)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 3\
**Last updated:** [June 19, 2025, 2:26am UTC](https://discourse.julialang.org/t/forwarddiff-allocations/130006 "2025-06-19T02:26:15Z")

</div>

I ran into a strange issue where very small changes to a non-allocating function affect whether it’s ForwardDiff.gradient! is allocating or not. Here is an MWE. It’s a vastly simplified version of my original structure,…

---

## [Read!( ) not working for HDF5 file](https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 1\
**Last updated:** [June 15, 2025, 11:46am UTC](https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722 "2025-06-15T11:46:24Z")

</div>

I have an HDF5 file. I want to read or allocate its data in variable r repeatedly instead of allocating in different places :seat: in memory. using HDF5 fname = tempname(); # temporary file fid = h5open(fname, "w") cre…

---

## [Is it possible to reinterpret and reshape without allocating?](https://discourse.julialang.org/t/is-it-possible-to-reinterpret-and-reshape-without-allocating/129842)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 11\
**Last updated:** [June 13, 2025, 9:18am UTC](https://discourse.julialang.org/t/is-it-possible-to-reinterpret-and-reshape-without-allocating/129842 "2025-06-13T09:18:28Z")

</div>

So I have data I’m getting over HTTP, r = rand(UInt8, 847296) It is arraigned in 3 8 byte chunks, where the first chunk is unwanted metadata, so every 3n -2 chunks is unwanted. I have written a function that does this…

---

## [DifferentialEquations.jl: Malloc errors in ODEProblems](https://discourse.julialang.org/t/differentialequations-jl-malloc-errors-in-odeproblems/129684)

<div class="topic-metadata">

**Author:** [@k-ray-liu](https://discourse.julialang.org/u/k-ray-liu)\
**Replies:** 6\
**Last updated:** [June 12, 2025, 10:59am UTC](https://discourse.julialang.org/t/differentialequations-jl-malloc-errors-in-odeproblems/129684 "2025-06-12T10:59:30Z")

</div>

Hi there, I’m having memory related problem when running the solver for ODEProblems, with the DifferentialEquations.jl package. It’s very inconsistent when the problem will arise (I’m scanning across a large number of …

---

## [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 …

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