# Proposal for deterministic memory management

**URL:** <https://discourse.julialang.org/t/proposal-for-deterministic-memory-management/39305>\
**Category:** Internals & Design\
**Created:** [May 10, 2020, 7:36am UTC](https://discourse.julialang.org/t/proposal-for-deterministic-memory-management/39305 "2020-05-10T07:36:34Z")\
**Posts on this page:** 1\
**Showing post:** 45

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [May 12, 2020, 11:40am UTC](https://discourse.julialang.org/t/proposal-for-deterministic-memory-management/39305/45 "2020-05-12T11:40:32Z")

</div>

We can make the previous example static by considering the worst case (outer scope). Scope of `a` and `b` can be found from the user’s code.

Worst case for this particular example is that v becomes global and so it should be deleted manually.

```julia
# lowered static code:
const global_var = [] # Var{:global}
function f(a,b)
    v = Any[1]
    rand(Bool) && push!(a, v)
    rand(Bool) && push!(b, v)  
    rand(Bool) && push!(global_var, v) # worst case v becomes Var{:global}
    rand(Bool) && push!(v, v)
    rand(Bool) ? do_something(v) : do_something_else(v)
end

# v should be deleted manually

```

---

_[View the full topic](https://discourse.julialang.org/t/proposal-for-deterministic-memory-management/39305)._
