- Compiler Escape Analysis decides whether or not whether an object stays on the stack or escapes to the stack
- If the lifetime of the object will outlive the stack frame
- If the compiler can’t prove it will outlive the stack
Usually an object is escaped to the heap when:
- A function is returning a pointer
- Storing a pointer to a heap-allocated object
- Passing a pointer to another function
- Closures2508102143