# Ref() which doesn't escape inside a function allocates on the heap

**URL:** <https://discourse.julialang.org/t/ref-which-doesnt-escape-inside-a-function-allocates-on-the-heap/58406>\
**Category:** Performance\
**Tags:** cuda, memory-allocation\
**Created:** [April 2, 2021, 12:30am UTC](https://discourse.julialang.org/t/ref-which-doesnt-escape-inside-a-function-allocates-on-the-heap/58406 "2021-04-02T00:30:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![balenamiaa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balenamiaa/32/23546_2.png) [@balenamiaa](https://discourse.julialang.org/u/balenamiaa)\
**Post date:** [April 2, 2021, 1:55am UTC](https://discourse.julialang.org/t/ref-which-doesnt-escape-inside-a-function-allocates-on-the-heap/58406/2 "2021-04-02T01:55:45Z")

</div>

from [https://discourse.julialang.org/t/how-to-know-if-object-memory-resides-on-stack-or-heap/4927/8](https://discourse.julialang.org/t/how-to-know-if-object-memory-resides-on-stack-or-heap/4927/8):

> And there are cases that’s currently considered escaping but may not in the future,
> 
> - used in function call to non-inlined function
> - stored to argument of non-inlined function

but I really don’t understand this limitation, and am surprised that “the future” isn’t now considering that was from 2017.

---

_[View the full topic](https://discourse.julialang.org/t/ref-which-doesnt-escape-inside-a-function-allocates-on-the-heap/58406)._
