# Disabling allocations

**URL:** <https://discourse.julialang.org/t/disabling-allocations/51028>\
**Category:** Performance\
**Created:** [December 1, 2020, 5:06am UTC](https://discourse.julialang.org/t/disabling-allocations/51028 "2020-12-01T05:06:54Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 3, 2020, 3:48pm UTC](https://discourse.julialang.org/t/disabling-allocations/51028/10 "2020-12-03T15:48:19Z")

</div>

Perhaps the manual is not clear. Check this example:

This is the code (file name here: test.jl):

```julia
struct A
  x
end

function test(n,x)
  y = Vector{A}(undef,n)
  for i in 1:n
    y[i] = A(i*x)
  end
  y
end

```

Run julia with:

```julia
julia --track-allocation=user

```

Within Julia, do:

```julia
julia> using Profile

julia> include("./test.jl")
test (generic function with 1 method)

julia> test(10,rand()); # gets compiled

julia> Profile.clear_malloc_data() # clear allocations

julia> test(10,rand());

```

Exit Julia, this will generate a file `test.jl.XXX.mem` (extension `.mem`), which, in this case, contains:

```julia
        -
        - struct A
        - x
        - end
        -
        - function test(n,x)
      160 y = Vector{A}(undef,n)
        0 for i in 1:n
      160 y[i] = A(i*x)
        - end
        0 y
        - end

```

Where the lines with non-zero numbers are the lines where allocations occur.

---

_[View the full topic](https://discourse.julialang.org/t/disabling-allocations/51028)._
