# Questions about memory allocation

**URL:** https://discourse.julialang.org/t/questions-about-memory-allocation/13416
**Category:** General Usage
**Created:** [August 14, 2018, 3:47am UTC](https://discourse.julialang.org/t/questions-about-memory-allocation/13416 "2018-08-14T03:47:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)
#### Post date: [August 14, 2018, 3:47am UTC](https://discourse.julialang.org/t/questions-about-memory-allocation/13416/1 "2018-08-14T03:47:57Z")

</div>

I ran julia with --track-allocation=user, and found some large memory allocations that I can’t understand. Can anyone please help explain?

1. What is going on with the for statement here:

```julia
        - function AtomValues(spec::Array{Float64,1}, attr::Attibutes, atom::Function,
        - iEnd=attr.len)
227767586 for i=1:iEnd
        0 spec[i] = atom(attr, i)
        - end
        0 nothing
        - end

```

1. What is happening with the if statement here? Sys is a “mutable struct”

```julia
        - function A_SCC_TB(i::Int, sys::Sys)
1821552352 if sys.csign == sys.Cond[i]
        - ProcessE(sys, i)
         - end
        0 nothing
        - end

```

Answer for 2): it was due to type mismatch. sys.csign was declared as ::Int64, and sys.Cond was declared as ::Array{Int64}. The latter needs to be changed to ::Array{Int64,1}, and then the allocation number becomes 0.

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [August 14, 2018, 5:55am UTC](https://discourse.julialang.org/t/questions-about-memory-allocation/13416/2 "2018-08-14T05:55:12Z")

</div>

I would expect that atom and ProecessE are allocating memory here. Have you checked these functions separately (eg with @btime)?

---

<div class="post-metadata">

### Author: ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)
#### Post date: [August 14, 2018, 8:21am UTC](https://discourse.julialang.org/t/questions-about-memory-allocation/13416/3 "2018-08-14T08:21:09Z")

</div>

Actually, in atom (a 1-line function that computes a value), there is no allocation. And in ProcessE, there are some minor allocations which don’t add up to the large number on the if statement.
