# Question About @allocated

**URL:** https://discourse.julialang.org/t/question-about-allocated/75155
**Category:** General Usage
**Created:** [January 25, 2022, 4:18am UTC](https://discourse.julialang.org/t/question-about-allocated/75155 "2022-01-25T04:18:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [January 25, 2022, 4:18am UTC](https://discourse.julialang.org/t/question-about-allocated/75155/1 "2022-01-25T04:18:07Z")

</div>

I am observing some behavior and I don’t understand it. I would appreciate any thoughts. For context, I’m using VSCode with the Julia extension, interactively evaluating each line of my code by highlighting it and pressing Shift+Enter.

This is the code.

```julia
A = rand(10)
B = rand(10)
C = rand(10)
D = zeros(Float64, 10)

function test_alloc(A, B, C, D)
    for j = 1:length(A)
        D[j] = B[j] * C[j]
    end
    sum!(A, D)
end

```

My expectation is that I will get zero heap allocations from this since no new arrays are created inside the function and no slices or views are made.

I check the allocation by doing `a = @allocated test_alloc(A, B, C, D)` and it tells me 1123001 bytes(?) were allocated. I then evaluate the line `a = @allocated test_alloc(A, B, C, D)` again, without changing anything, and it says 0 bytes. I’m wondering, why does it change when I evaluate it the second time?

I also note that when I do `@btime test_alloc($A, $B, $C, $D)` the result is 0 allocations as I expect.

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [January 25, 2022, 5:12am UTC](https://discourse.julialang.org/t/question-about-allocated/75155/2 "2022-01-25T05:12:47Z")

</div>

It compiles the first time.  
Compilation allocates.

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [January 26, 2022, 1:11am UTC](https://discourse.julialang.org/t/question-about-allocated/75155/3 "2022-01-26T01:11:39Z")

</div>

Thanks - that helped. I also found [this](https://discourse.julialang.org/t/so-does-julia-compile-or-interpret/56073/2) post which filled in the remaining gaps I had.
