# Help: OutOfMemoryError()

**URL:** <https://discourse.julialang.org/t/help-outofmemoryerror/70396>\
**Category:** New to Julia\
**Created:** [October 26, 2021, 10:42am UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396 "2021-10-26T10:42:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Temi-Tory](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/temi-tory/32/29716_2.png) [@Temi-Tory](https://discourse.julialang.org/u/Temi-Tory)\
**Post date:** [October 26, 2021, 10:42am UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/1 "2021-10-26T10:42:27Z")

</div>

Hi I am new to still new to Julia and I have encountered this error and I cant figure out what is causing it and why.  
Below is my code. The first time I ran this, it was executed fine but after that I keep getting this out of memory error.

```julia
function logistic_dot(x,beta ,alpha = 0)
    return @. 1.0/(1.0+exp((beta*x) + alpha))
end

temperature = challenger_data_new[:,1]
D = challenger_data_new[:,2]

@model function challenger(data,temperature) #Turing model for challenger data info 
    β ~ Normal(0,10)
    α ~ Normal(0,10)
    p = @. 1/(1+exp((temperature*β)+α)) # p(t)= 1/(1+eᵝᵗ⁺ᵅ)
    for i in eachindex(p)
        data[i] ~ Bernoulli(p[i])
    end
    return p
end

model = challenger(D,temperature)   
map_estimate = optimize(model, MAP())
trace = sample(model,MH(),1000000, init_theta = map_estimate.values.array)

β_samples = trace[:β];
α_samples = trace[:α];

t = LinRange(minimum(temperature) -5,maximum(temperature)+5,50)
p_t = logistic_dot(transpose(t),β_samples,α_samples)
mean_prob_t = mean(p_t,dims = 1)[:]

```

The issue seems to be with the logistic\_dot function

---

<div class="post-metadata">

**Author:** ![vinicius\_de\_lima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinicius_de_lima/32/28717_2.png) [@vinicius\_de\_lima](https://discourse.julialang.org/u/vinicius_de_lima)\
**Post date:** [October 26, 2021, 11:23am UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/2 "2021-10-26T11:23:57Z")

</div>

Could you post the complete error message?

---

<div class="post-metadata">

**Author:** ![Temi-Tory](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/temi-tory/32/29716_2.png) [@Temi-Tory](https://discourse.julialang.org/u/Temi-Tory)\
**Post date:** [October 26, 2021, 12:23pm UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/3 "2021-10-26T12:23:49Z")

</div>

ERROR: LoadError: OutOfMemoryError()  
Stacktrace:  
[1] Array  
@ .\boot.jl:450 [inlined]  
[2] Array  
@ .\boot.jl:458 [inlined]  
[3] Array  
@ .\boot.jl:465 [inlined]  
[4] similar  
@ .\abstractarray.jl:785 [inlined]  
[5] similar  
@ .\abstractarray.jl:784 [inlined]  
[6] similar  
@ .\broadcast.jl:197 [inlined]  
[7] similar  
@ .\broadcast.jl:196 [inlined]  
[8] copy  
@ .\broadcast.jl:908 [inlined]  
[9] materialize  
@ .\broadcast.jl:883 [inlined]  
[10] logistic\_dot(x::LinearAlgebra.Transpose{Float64, LinRange{Float64}}, beta::AxisArrays.AxisArray{Float64, 2, Matrix{Float64}, Tuple{AxisArrays.Axis{:iter, StepRange{Int32, Int32}}, AxisArrays.Axis{:chain, UnitRange{Int32}}}}, alpha::AxisArrays.AxisArray{Float64, 2, Matrix{Float64}, Tuple{AxisArrays.Axis{:iter, StepRange{Int32, Int32}}, AxisArrays.Axis{:chain, UnitRange{Int32}}}})  
@ Main c:\Users\ohian\OneDrive - University of Strathclyde\Documents\Julia Files\Bayesian Methods\Chapter2\Challenger\_Spac\_ Shuttle\_Disaster\_Example.jl:36  
[11] top-level scope  
@ c:\Users\ohian\OneDrive - University of Strathclyde\Documents\Julia Files\Bayesian Methods\Chapter2\Challenger\_Spac\_ Shuttle\_Disaster\_Example.jl:91  
in expression starting at c:\Users\Julia Files\Bayesian Methods\Chapter2\Challenger\_Spac\_ Shuttle\_Disaster\_Example.jl:91

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [October 26, 2021, 3:18pm UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/4 "2021-10-26T15:18:12Z")

</div>

You’re trying to sample 1 million vectors with dimension `size(challenger_data_new,1)`, and I guess you computer doesn’t have enough memory to store that result (that’s what `OutOfMemoryError` means). You either need to reduce the number of samples or get a bigger computer 🙂

---

<div class="post-metadata">

**Author:** ![Temi-Tory](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/temi-tory/32/29716_2.png) [@Temi-Tory](https://discourse.julialang.org/u/Temi-Tory)\
**Post date:** [October 26, 2021, 4:00pm UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/5 "2021-10-26T16:00:51Z")

</div>

Thank you!

Guess I must keep that in mind when sampling until i get a better PC. 😁

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 26, 2021, 4:22pm UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/6 "2021-10-26T16:22:57Z")

</div>

the other answer is that this code could probably be written to not allocate nearly as much as it currently does.

---

<div class="post-metadata">

**Author:** ![Temi-Tory](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/temi-tory/32/29716_2.png) [@Temi-Tory](https://discourse.julialang.org/u/Temi-Tory)\
**Post date:** [October 28, 2021, 3:59pm UTC](https://discourse.julialang.org/t/help-outofmemoryerror/70396/7 "2021-10-28T15:59:59Z")

</div>

Could you please elaborate on this?  
I am still new to Julia and I’m currently following a Turing tutorial as a basis for this code
