# Memory allocations

**URL:** <https://discourse.julialang.org/t/memory-allocations/114499>\
**Category:** New to Julia\
**Created:** [May 21, 2024, 9:24am UTC](https://discourse.julialang.org/t/memory-allocations/114499 "2024-05-21T09:24:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucasMontoya4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmontoya4/32/205442_2.png) [@LucasMontoya4](https://discourse.julialang.org/u/LucasMontoya4)\
**Post date:** [May 21, 2024, 9:24am UTC](https://discourse.julialang.org/t/memory-allocations/114499/1 "2024-05-21T09:24:52Z")

</div>

Hi there, I was wondering why the line `@allocated A = 100` gives 0, whereas `@allocated B = [1,2,3,4,5]` gives 96. Both can result in a completely fresh REPL, so why does defining `A = 100` not use any memory? Surely the information of the value that A has been assigned needs to be stored somewhere?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 21, 2024, 9:47am UTC](https://discourse.julialang.org/t/memory-allocations/114499/2 "2024-05-21T09:47:25Z")

</div>

Hi Lucas!  
The number returned by `@allocated` actually corresponds to the number of bytes allocated on the “heap”, as opposed to the “stack”. Roughly speaking, Julia allocates immutable objects (like integers) on the stack, which is very fast, but mutable objects (like vectors) on the heap, which is much slower.  
When we want to optimize the performance of a code, usually we seek to reduce heap allocations, and that is why `@allocated` focuses on those.

---

<div class="post-metadata">

**Author:** ![LucasMontoya4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmontoya4/32/205442_2.png) [@LucasMontoya4](https://discourse.julialang.org/u/LucasMontoya4)\
**Post date:** [May 22, 2024, 4:25pm UTC](https://discourse.julialang.org/t/memory-allocations/114499/3 "2024-05-22T16:25:08Z")

</div>

I didn’t know that - that clears things up, thank you!
