| ▲ | foldr 3 days ago | ||||||||||||||||
I mean that escape analysis has nothing to do with my example either, in terms of understand the semantics of the code (so I’m disagreeing with the ‘because GC and escape analysis’ part of your comment). | |||||||||||||||||
| ▲ | knorker 3 days ago | parent [-] | ||||||||||||||||
Your https://news.ycombinator.com/item?id=46234206 relies on escape analysis though, right? Escape analysis is the reason your `x` is on the heap. Because it escaped. Otherwise it'd be on the stack.[1] Now if by "semantics of the code" you mean "just pretend everything is on the heap, and you won't need to think about escape analysis", then sure. Now in terms of what actually happens, your code triggers escape analysis, and OP does not. [1] Well, another way to say this I guess is that without escape analysis, a language would be forced to never use the stack. | |||||||||||||||||
| |||||||||||||||||