# How the compiler decides which allocation is eliminated?

**URL:** <https://discourse.julialang.org/t/how-the-compiler-decides-which-allocation-is-eliminated/123127>\
**Category:** Internals & Design\
**Created:** [November 26, 2024, 9:43pm UTC](https://discourse.julialang.org/t/how-the-compiler-decides-which-allocation-is-eliminated/123127 "2024-11-26T21:43:20Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [November 26, 2024, 10:37pm UTC](https://discourse.julialang.org/t/how-the-compiler-decides-which-allocation-is-eliminated/123127/4 "2024-11-26T22:37:55Z")

</div>

The only other error Jeff and I can think of that isn’t modeled is StackOverflow. (The reasoning is that ~any code theoretically can throw those, and they don’t exist within the Turing machine model of a machine).

For your followup, see [make `memorynew` intrinsic by oscardssmith · Pull Request #55913 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/55913) which does make `foo4` removable (but isn’t quite able to remove `foo5`)

```julia
function foo5()
    v = Vector{Int}(undef, 2^50)
    v[1] = 5
    v[1]
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-the-compiler-decides-which-allocation-is-eliminated/123127)._
