# Understanding allocations reported by --track-allocation (solved)

**URL:** <https://discourse.julialang.org/t/understanding-allocations-reported-by-track-allocation-solved/134628>\
**Category:** General Usage\
**Created:** [December 18, 2025, 11:10am UTC](https://discourse.julialang.org/t/understanding-allocations-reported-by-track-allocation-solved/134628 "2025-12-18T11:10:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Post date:** [December 18, 2025, 11:10am UTC](https://discourse.julialang.org/t/understanding-allocations-reported-by-track-allocation-solved/134628/1 "2025-12-18T11:10:34Z")

</div>

I’m trying to understand the output of `--track-allocation=user` on this very straightforward snippet:

```julia-auto
mutable struct S
    n
    positions
end

function S(n)
    return S(n, zeros(Float32,n))
end

function (@main)(args)
    N = 100
    s = S(N)

    for i in 1:N
        s.positions[i] += 1f0
    end
end

```

Does the `s.positions[i] += 1f0` really allocate 32 bytes per execution? Or is this something that the allocation tracking is not reporting correctly?

```julia-auto
        - mutable struct S
        - n
        - positions
        - end
        - 
        - function S(n)
        - return S(n, zeros(Float32,n))
        - end
        - 
        - function (@main)(args)
        - N = 100
      480 s = S(N)
        - 
        0 for i in 1:N
     3200 s.positions[i] += 1f0
        0 end
        - end

```

```julia-auto
Julia Version 1.12.3
Commit 966d0af0fdf (2025-12-15 11:20 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, skylake)
  GC: Built with stock GC
Threads: 8 default, 1 interactive, 8 GC (on 8 virtual cores)
Environment:
  JULIA_PKG_USE_CLI_GIT = true
  JULIA_NUM_THREADS = auto

```

Edit: ah, it’s the mutability of the struct causing it

```julia-auto
        - struct S
        - n
        - positions
        - end
        - 
        - function S(n)
        - return S(n, zeros(Float32,n))
        - end
        - 
        - function (@main)(args)
        - N = 100
      480 s = S(N)
        - 
        0 for i in 1:N
        0 s.positions[i] += 1f0
        0 end
        - end

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [December 18, 2025, 11:48am UTC](https://discourse.julialang.org/t/understanding-allocations-reported-by-track-allocation-solved/134628/2 "2025-12-18T11:48:21Z")

</div>

As a side note, try to always type the fields of a struct, otherwise you will get `Any` fields, which can lead to poor performance. You can add type parameters to let the compiler figure out the types for you:

```julia
struct S{N,P}
  n::N
  positions::P
end

```
