# \#allocations

**URL:** https://discourse.julialang.org/tag/allocations/818.md

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

---

## [Why check\_allocs warns about reliability?](https://discourse.julialang.org/t/why-check-allocs-warns-about-reliability/137660)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 0\
**Last updated:** [June 16, 2026, 6:32pm UTC](https://discourse.julialang.org/t/why-check-allocs-warns-about-reliability/137660 "2026-06-16T18:32:38Z")

</div>

The docstring for check\_allocs in AllocCheck.jl warns, in part: If you rely on allocation-free code for safety/correctness, it is not sufficient to verify check\_allocs in test code and expect that the corresponding cal…

---

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

---

## [\`@allocated\` vs \`@allocations\`](https://discourse.julialang.org/t/allocated-vs-allocations/134408)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 2\
**Last updated:** [December 7, 2025, 8:36am UTC](https://discourse.julialang.org/t/allocated-vs-allocations/134408 "2025-12-07T08:36:06Z")

</div>

Since 1.9, Julia has @allocations, which is A macro to evaluate an expression, discard the resulting value, and instead return the total number of allocations during evaluation of the expression. In contrast, @alloca…

---

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

---

## [Optimisation over grid of parameters with \`Optimization.jl\`](https://discourse.julialang.org/t/optimisation-over-grid-of-parameters-with-optimization-jl/131571)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 7\
**Last updated:** [August 18, 2025, 10:28pm UTC](https://discourse.julialang.org/t/optimisation-over-grid-of-parameters-with-optimization-jl/131571 "2025-08-18T22:28:49Z")

</div>

I am trying to solve a low dimensional (box-)constrained optimisation problem over a large grid of parameters. Both the optimisation problem and the constraints depend on the parameters. I can assume that the optimisatio…

---

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

---

## [Avoid allocations in one-dimensional Optim when target expects vector](https://discourse.julialang.org/t/avoid-allocations-in-one-dimensional-optim-when-target-expects-vector/131159)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 5\
**Last updated:** [July 29, 2025, 8:48am UTC](https://discourse.julialang.org/t/avoid-allocations-in-one-dimensional-optim-when-target-expects-vector/131159 "2025-07-29T08:48:35Z")

</div>

Hi, I’m in an optimization situation where I have an objective function that expects a vector input, but the optimization problem is over just one variable, so I’d like to use Brent’s algorithm. To make it compatible wit…

---

## [Kwargs... and allocations](https://discourse.julialang.org/t/kwargs-and-allocations/129183)

<div class="topic-metadata">

**Author:** [@Allan\_Baker](https://discourse.julialang.org/u/Allan_Baker)\
**Replies:** 26\
**Last updated:** [May 21, 2025, 3:05pm UTC](https://discourse.julialang.org/t/kwargs-and-allocations/129183 "2025-05-21T15:05:49Z")

</div>

I recently was trying to overload some real-time code (meaning I don’t want any GC or allocations). I needed to add in some kwargs to the help with overloading some intermediate functions. This causes allocations becau…

---

## [Enzyme custom rule alloactions](https://discourse.julialang.org/t/enzyme-custom-rule-alloactions/128491)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 0\
**Last updated:** [April 28, 2025, 2:11pm UTC](https://discourse.julialang.org/t/enzyme-custom-rule-alloactions/128491 "2025-04-28T14:11:20Z")

</div>

Hello, I got a problem with allocations when using custom rules in Enzyme. The example below is just a toy example but the same problem arises there. In total I get 4 alloactions. 2 by the line primal = func.val(y.va…

---

## [Reducing the number of allocations in a function](https://discourse.julialang.org/t/reducing-the-number-of-allocations-in-a-function/126906)

<div class="topic-metadata">

**Author:** [@andrea\_bertozzi](https://discourse.julialang.org/u/andrea_bertozzi)\
**Replies:** 14\
**Last updated:** [March 14, 2025, 12:30pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-allocations-in-a-function/126906 "2025-03-14T12:30:39Z")

</div>

Hello, I have this function. When running benchmark, I get 519 allocations. Does anyone know how I can reduce those? Thank you! using LinearAlgebra struct Settings rho::Float64 g\_earth::Vector{Float64} cd…

---

## [Performance regression on v1.12 (nightly): \`hypot(::Float64, ::Float64)\` causes allocations](https://discourse.julialang.org/t/performance-regression-on-v1-12-nightly-hypot-float64-float64-causes-allocations/123871)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [December 16, 2024, 5:41am UTC](https://discourse.julialang.org/t/performance-regression-on-v1-12-nightly-hypot-float64-float64-causes-allocations/123871 "2024-12-16T05:41:56Z")

</div>

I don’t have a MWE yet (tried but failed as of yet), mostly writing this so I wouldn’t forget to make an actual bug report later. I have some code, and profiling it on Julia nightly show that this line allocates Float64 …

---

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

---

## [Mutating a StructArray without allocation](https://discourse.julialang.org/t/mutating-a-structarray-without-allocation/121311)

<div class="topic-metadata">

**Author:** [@prconlin](https://discourse.julialang.org/u/prconlin)\
**Replies:** 5\
**Last updated:** [October 16, 2024, 1:44pm UTC](https://discourse.julialang.org/t/mutating-a-structarray-without-allocation/121311 "2024-10-16T13:44:26Z")

</div>

Hello, I’m trying to use StructArrays.jl as a fast, convenient solution for working with coordinate data. But I’m having difficulty operating on StructArrays in the way I had hoped I could. Here is a MWE of what I’m t…

---

## [Proving that copyto! is allocation-free on a view, using AllocCheck](https://discourse.julialang.org/t/proving-that-copyto-is-allocation-free-on-a-view-using-alloccheck/121318)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 7\
**Last updated:** [October 15, 2024, 3:21pm UTC](https://discourse.julialang.org/t/proving-that-copyto-is-allocation-free-on-a-view-using-alloccheck/121318 "2024-10-15T15:21:11Z")

</div>

Hi there, I wanted to add allocation checks to the DifferentiationInterface.jl test suite, but the code for my in-place jacobian! involves copying a vector into a matrix column. Unfortunately, AllocCheck.jl cannot guara…

---

## [Selecting entries of an array based on selection criteria provided by other array](https://discourse.julialang.org/t/selecting-entries-of-an-array-based-on-selection-criteria-provided-by-other-array/118632)

<div class="topic-metadata">

**Author:** [@oscarvdvelde](https://discourse.julialang.org/u/oscarvdvelde)\
**Replies:** 10\
**Last updated:** [August 28, 2024, 8:35pm UTC](https://discourse.julialang.org/t/selecting-entries-of-an-array-based-on-selection-criteria-provided-by-other-array/118632 "2024-08-28T20:35:36Z")

</div>

Consider this example, which may run in a loop where selection is updated. a = \[1.0,1.2,0.9, 3.4, 4.5,4.5, 9.7, -1.5,-2.1\] b = \[1,1,1,2,3,3,4,5,5\] # e.g. a grouping of a selection = \[1,3,5\] # these groups # What I…

---

## [Reduce allocations in 'reduce + eachcol' call to multiply several columns elementwise](https://discourse.julialang.org/t/reduce-allocations-in-reduce-eachcol-call-to-multiply-several-columns-elementwise/118234)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 6\
**Last updated:** [August 16, 2024, 2:05pm UTC](https://discourse.julialang.org/t/reduce-allocations-in-reduce-eachcol-call-to-multiply-several-columns-elementwise/118234 "2024-08-16T14:05:26Z")

</div>

Hi, I find that using reduce + eachcol in the following allocates more than I would like. The point is to element-wise multiply some columns of X. I’m getting n allocations where n is the number of rows when using reduce …

---

## [Allocation-efficient calculation of Hermite (and Laguerre) polynomials](https://discourse.julialang.org/t/allocation-efficient-calculation-of-hermite-and-laguerre-polynomials/118220)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 5\
**Last updated:** [August 16, 2024, 7:45am UTC](https://discourse.julialang.org/t/allocation-efficient-calculation-of-hermite-and-laguerre-polynomials/118220 "2024-08-16T07:45:54Z")

</div>

un-XY: I’m working on a project that involves a lot of simulation, for which I need to compute basis-functions based on the simulated quantities repeatedly. I’m writing code that allows me to flexibly mix-and-match vario…

---

## [Weird results while trying to measure allocation :/](https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [August 2, 2024, 12:19am UTC](https://discourse.julialang.org/t/weird-results-while-trying-to-measure-allocation/117745 "2024-08-02T00:19:16Z")

</div>

Consider this Julia program: f() = Vector{Int}(undef, 128\*1024\*1024) (@timed f()).bytes (r = @timed f()); r.bytes Why do recent versions of Julia (v1.8 and up) evaluate the second line as 0? It really seems like the se…

---

## [Create SVector with one non-zero value](https://discourse.julialang.org/t/create-svector-with-one-non-zero-value/116295)

<div class="topic-metadata">

**Author:** [@Alseidon](https://discourse.julialang.org/u/Alseidon)\
**Replies:** 11\
**Last updated:** [June 27, 2024, 2:03pm UTC](https://discourse.julialang.org/t/create-svector-with-one-non-zero-value/116295 "2024-06-27T14:03:16Z")

</div>

I am trying to define a function fc(i) returning a fixed size SVector with zeros everywhere, and a 1 at position i. Is it possible to do this with no allocations, and type stability? My first two tries either were type u…

---

## [Elimination of (unnecessary) runtime dispatch allocations](https://discourse.julialang.org/t/elimination-of-unnecessary-runtime-dispatch-allocations/113475)

<div class="topic-metadata">

**Author:** [@nielsls](https://discourse.julialang.org/u/nielsls)\
**Replies:** 13\
**Last updated:** [May 5, 2024, 12:00pm UTC](https://discourse.julialang.org/t/elimination-of-unnecessary-runtime-dispatch-allocations/113475 "2024-05-05T12:00:26Z")

</div>

Avoiding runtime dispatch is perhaps the #1 optimization advice in Julia forums. As I understand it, the reason is that when the Julia compiler does a runtime dispatch it does not at compile-time neccesarily know the re…

---

## [Why does b \*= A\[r\] allocate memory?](https://discourse.julialang.org/t/why-does-b-a-r-allocate-memory/106279)

<div class="topic-metadata">

**Author:** [@Christopher\_White](https://discourse.julialang.org/u/Christopher_White)\
**Replies:** 6\
**Last updated:** [November 15, 2023, 9:29pm UTC](https://discourse.julialang.org/t/why-does-b-a-r-allocate-memory/106279 "2023-11-15T21:29:32Z")

</div>

The following code does a whole bunch of allocations: N = 10000000 A = randn(Float64, N) b = 1.0 @show typeof(b) @time for r = 1:N b \*= A\[r\] end Why is that? How can I write this in a way that doesn’t allocate ~ a…

---

## [Why so many allocations in the loop on partition](https://discourse.julialang.org/t/why-so-many-allocations-in-the-loop-on-partition/101606)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 7\
**Last updated:** [July 14, 2023, 5:39pm UTC](https://discourse.julialang.org/t/why-so-many-allocations-in-the-loop-on-partition/101606 "2023-07-14T17:39:47Z")

</div>

Maybe I do the measurements wrong, but I’m surprised that partition performs so badly in this case. using IterTools, BenchmarkTools a=rand(1:10,10^5) function looppart(a) res=zeros(Int,20) for (a1,a2) in partition(a,2,…

---

## [Need help understanding allocations while calling external C library (Proj)](https://discourse.julialang.org/t/need-help-understanding-allocations-while-calling-external-c-library-proj/101133)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 3\
**Last updated:** [July 4, 2023, 5:15pm UTC](https://discourse.julialang.org/t/need-help-understanding-allocations-while-calling-external-c-library-proj/101133 "2023-07-04T17:15:33Z")

</div>

Hello everyone, I have been scratching my head around allocations I have in a package I am developing that I can’t seem to eliminate. Moreover it seems that the allocation results I get from @allocations and @btime fro…

---

## [Adding Plotly Traces to an Array](https://discourse.julialang.org/t/adding-plotly-traces-to-an-array/75889)

<div class="topic-metadata">

**Author:** [@pimler73](https://discourse.julialang.org/u/pimler73)\
**Replies:** 6\
**Last updated:** [May 8, 2023, 7:33pm UTC](https://discourse.julialang.org/t/adding-plotly-traces-to-an-array/75889 "2023-05-08T19:33:22Z")

</div>

I am attempting to plot multiple traces using the PlotlyJS backend and there are too many to do manually. My idea is to do something of the sort: for idx in 1:size(data)\[2\] traces\[idx\] = scatter(x=r\_range, …

---

## [Performance of function with pre-allocated outputs](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457)

<div class="topic-metadata">

**Author:** [@jekyllstein](https://discourse.julialang.org/u/jekyllstein)\
**Replies:** 3\
**Last updated:** [May 8, 2023, 8:19am UTC](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457 "2023-05-08T08:19:37Z")

</div>

Consider the following mutating function that mutates a vector input: function f\_test!(xout::Vector{T}, a::T, b::T) where T \<: Real xout .= a .\* b view(xout, 1:max(1, lastindex(xout)-5)) .-= b return xout end I time…

---

## [High allocations count for TwoPointBVProblem in DifferentialEquations.jl](https://discourse.julialang.org/t/high-allocations-count-for-twopointbvproblem-in-differentialequations-jl/96296)

<div class="topic-metadata">

**Author:** [@Hawkes](https://discourse.julialang.org/u/Hawkes)\
**Replies:** 4\
**Last updated:** [March 19, 2023, 11:22am UTC](https://discourse.julialang.org/t/high-allocations-count-for-twopointbvproblem-in-differentialequations-jl/96296 "2023-03-19T11:22:52Z")

</div>

Hi, I’m currently trying to port some simulation code from Python to Julia. The Python version uses scipy’s solve\_bvp function to solve a two point boundary value problem. I am using DifferentialEquations.jl to accompl…

---

## [Preallocating Interpolation object](https://discourse.julialang.org/t/preallocating-interpolation-object/96207)

<div class="topic-metadata">

**Author:** [@tradler](https://discourse.julialang.org/u/tradler)\
**Replies:** 3\
**Last updated:** [March 16, 2023, 9:40pm UTC](https://discourse.julialang.org/t/preallocating-interpolation-object/96207 "2023-03-16T21:40:02Z")

</div>

I am solving a dynamic programing value function using backward induction, and would like to be able to update an Interpolations.jl object (or something similar) which holds an approximation of the value function in each…

---

## [Inplace multiplication of sub-matrices without allocations](https://discourse.julialang.org/t/inplace-multiplication-of-sub-matrices-without-allocations/91534)

<div class="topic-metadata">

**Author:** [@CeterisPartybus](https://discourse.julialang.org/u/CeterisPartybus)\
**Replies:** 12\
**Last updated:** [December 12, 2022, 8:44pm UTC](https://discourse.julialang.org/t/inplace-multiplication-of-sub-matrices-without-allocations/91534 "2022-12-12T20:44:36Z")

</div>

I am writing a performance-critical part and would like to avoid any memory allocations in that part by creating caches beforehand. I then essentially need to multiply sub-arrays in a loop. Is there any way to do these m…

---

## [Allocations (again...)](https://discourse.julialang.org/t/allocations-again/90780)

<div class="topic-metadata">

**Author:** [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Replies:** 15\
**Last updated:** [November 25, 2022, 2:26pm UTC](https://discourse.julialang.org/t/allocations-again/90780 "2022-11-25T14:26:34Z")

</div>

When I run using BenchmarkTools function test(x, Y) sum!(x, Y') return nothing end x = rand(Float64, 100) Y = rand(Float64, 1, 100) @btime(test(x, Y)) I get the following: 367.952 ns (2 allocations: 96 bytes…

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